Re: How (or why) does this bash script snippet work?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 12Jan2012 19:07, Dean S. Messing <deanm@xxxxxxxxxxxxx> wrote:
| On 13 Jan 2012 at 13:55:27, Cameron Simpson wrote:
| <snip>
| > The:
| > 
| >   <foo command [args...]
| > 
| > form is handy for programmatically constructed pipelines, too.
| 
| Sorry, I don't understand "programmatically constructed pipelines".
| Would you elaborate?  Thanks

Where one has a script that figures out a pipeline and assembles it.
So one might have a file conversion tool that goes:

  my-convert-script src-file dst-file change1 change2 change3 ...

which goes:

  src=$1; shift
  dst=$2; shift

  shcmd="<\"\$src\" cat"
  for change
  do
    case "$change" in
      a)        conv="cmd-to-do-change-a" ;;
      b)        conv="some-other-command-to-do-change-b" ;;
    esac
    shcmd="$shcmd | $conv"
  done
  shcmd="$shcmd >\"\$dst\""

  sh -c "$shcmd"

This builds a shell pipeline command, starting with the input
redirection, adding pipes to munge the data, then adding the output
redirection. (Obviously there's no error checking etc above, and the
"cat" can be optimised out, etc.)

Cheers,
-- 
Cameron Simpson <cs@xxxxxxxxxx> DoD#743
http://www.cskk.ezoshosting.com/cs/

And it is not our part here to take thought only for a season, or for a few
lives of Men, or for a passing age of the world.        - Gandalf the grey
-- 
users mailing list
users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
Have a question? Ask away: http://ask.fedoraproject.org


[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux