Tag Info

New answers tagged


You may use getopts in bash which can parse the arguments for you, e.g.: while getopts a:b: opts; do case ${opts} in a) A=${OPTARG} ;; b) B=${OPTARG} ;; esac done


This is bad code. getopt is pretty much unusable┬╣. Use the getopts shell builtin instead (it has two advantages: it can work, and it's available on all POSIX platforms). What args=$(getopt optstring $*); set -- $args does is: Split each command line argument at whitespace and replace it by the list of whitespace-delimited words. Take each of the resulting ...


set -- $args set the positional arguments base on content of $args. Now you will get the different behavior between zsh and other POSIX shells. Because zsh does not perform Field Splitting by default, you will get one string, which is content of$args. You must to call splitting explicitly to get the same behavior as bash (and also other POSIX shells): set ...


You can achieve what you want with: cat footest.arg | xargs ./foo or (thanks to @glenn) xargs ./foo < footest.arg avoiding one unnecessary use of cat.


You want to take output of a command and transform it into arguments. Try command substitution: ./foo $(< footest.args)


If you have var1=foo and foo=bar, you can get bar by saying ${!var1}. However, if you want to iterate over the positional parameters, it's almost certainly better to do for i in "$@"; do # something done


In bash, the argument separators are spaces, so : instead of : x_pos="$(convert_coordinates $x_pos, $x_marg, $x_grid, $x_max)" do x_pos="$(convert_coordinates $x_pos $x_marg $x_grid $x_max)"


You might have some success with .bash() { emulate bash -c "$(echo ${(qq)@})" }

Top 50 recent answers are included