Tag Info

New answers tagged

2

You can use the $# special variable, to test the number of arguments given to a command: usage() { echo "Usage: $0 arg" exit 1 } if [[ "$#" -eq 0 ]]; then usage fi echo "called with $1" exit 0 When executed, this scripts gives: $ ./foo.sh Usage: ./foo.sh arg $ ./foo.sh bar called with bar


7

set -- is what you need: $ set -- aaa bbb ccc $ echo "$1" aaa $ echo "$2" bbb $ echo "$3" ccc $ echo "$@" aaa bbb ccc


11

The first argument after sh -c inline-script goes to $0 (which is also used for error messages), and the rest go in $1, $2... $ sh -c 'blah; echo "$0"; echo "$1"' my-inline-script arg my-inline-script: blah: command not found my-inline-script arg So you want: sh -c 'find "$1"' sh /tmp (in the olden days, you could find sh implementations where the ...



Top 50 recent answers are included