Skip to main content
Rollback to Revision 3 - Edit approval overridden by post owner or moderator
Source Link
user732
user732

The shell command and any arguments to that command appear as numbered shell variables: $0 has the string value of the command itself, something like script, ./script, /home/user/bin/script or whatever. Any arguments appear as "$1", "$2", "$3" and so on. The count of arguments is in the shell variable "$#".

  • $0 has the string value of the command itself, something like script, ./script, /home/user/bin/script or whatever.
  • Any arguments appear as "$1", "$2", "$3" and so on. The count of arguments is in the shell variable "$#".

Common ways of dealing with this involve shell commands getopts and shift. getopts is a lot like the C getopt() library function. shift moves the value of $2 to $1, $3 to $2, and so on; $# gets decremented. Code ends up looking at the value of "$1", doing things using a caseesac to decide on an action, and then doing a shift to move $1 to the next argument. It only ever has to examine $1, and maybe $#.

The shell command and any arguments to that command appear as numbered shell variables:

  • $0 has the string value of the command itself, something like script, ./script, /home/user/bin/script or whatever.
  • Any arguments appear as "$1", "$2", "$3" and so on. The count of arguments is in the shell variable "$#".

Common ways of dealing with this involve shell commands getopts and shift. getopts is a lot like the C getopt() library function. shift moves the value of $2 to $1, $3 to $2, and so on; $# gets decremented. Code ends up looking at the value of "$1", doing things using a caseesac to decide on an action, and then doing a shift to move $1 to the next argument. It only ever has to examine $1, and maybe $#.

The shell command and any arguments to that command appear as numbered shell variables: $0 has the string value of the command itself, something like script, ./script, /home/user/bin/script or whatever. Any arguments appear as "$1", "$2", "$3" and so on. The count of arguments is in the shell variable "$#".

Common ways of dealing with this involve shell commands getopts and shift. getopts is a lot like the C getopt() library function. shift moves the value of $2 to $1, $3 to $2, and so on; $# gets decremented. Code ends up looking at the value of "$1", doing things using a caseesac to decide on an action, and then doing a shift to move $1 to the next argument. It only ever has to examine $1, and maybe $#.

The shell command and any arguments to that command appear as numbered shell variables: $0 has the string value of the command itself, something like script, ./script, /home/user/bin/script or whatever. Any arguments appear as "$1", "$2", "$3" and so on. The count of arguments is in the shell variable "$#".

  • $0 has the string value of the command itself, something like script, ./script, /home/user/bin/script or whatever.
  • Any arguments appear as "$1", "$2", "$3" and so on. The count of arguments is in the shell variable "$#".

Common ways of dealing with this involve shell commands getopts and shift. getopts is a lot like the C getopt() library function. shift moves the value of $2 to $1, $3 to $2, and so on; $# gets decremented. Code ends up looking at the value of "$1", doing things using a caseesac to decide on an action, and then doing a shift to move $1 to the next argument. It only ever has to examine $1, and maybe $#.

The shell command and any arguments to that command appear as numbered shell variables: $0 has the string value of the command itself, something like script, ./script, /home/user/bin/script or whatever. Any arguments appear as "$1", "$2", "$3" and so on. The count of arguments is in the shell variable "$#".

Common ways of dealing with this involve shell commands getopts and shift. getopts is a lot like the C getopt() library function. shift moves the value of $2 to $1, $3 to $2, and so on; $# gets decremented. Code ends up looking at the value of "$1", doing things using a caseesac to decide on an action, and then doing a shift to move $1 to the next argument. It only ever has to examine $1, and maybe $#.

The shell command and any arguments to that command appear as numbered shell variables:

  • $0 has the string value of the command itself, something like script, ./script, /home/user/bin/script or whatever.
  • Any arguments appear as "$1", "$2", "$3" and so on. The count of arguments is in the shell variable "$#".

Common ways of dealing with this involve shell commands getopts and shift. getopts is a lot like the C getopt() library function. shift moves the value of $2 to $1, $3 to $2, and so on; $# gets decremented. Code ends up looking at the value of "$1", doing things using a caseesac to decide on an action, and then doing a shift to move $1 to the next argument. It only ever has to examine $1, and maybe $#.

formatting; suggest getopts rather than getopt
Source Link
Gilles 'SO- stop being evil'
  • 865.3k
  • 205
  • 1.8k
  • 2.3k

The shell command and any arguments to that command appear as numbered shell variables: $0$0 has the string value of the command itself, something like "script"script, "./script"./script, "/home/user/bin/script"/home/user/bin/script or whatever. Any arguments appear as "$1""$1", "$2""$2", "$3""$3" and so on. The count of arguments is in the shell variable "$#""$#".

Common ways of dealing with this involve shell commands getoptgetopts and shift. getoptgetopts is a lot like the C getopt() library function. shift moves the value of $2$2 to $1$1, $3$3 to $2$2, and so on. $#on; $# gets decremented. Code ends up looking at the value of $1"$1", doing things using a case-esac to decide on an action, and then doing a shift to move $0$1 to the next argument. It only ever has to examine $0$1, and maybe $#$#.

The shell command and any arguments to that command appear as numbered shell variables: $0 has the string value of the command itself, something like "script", "./script", "/home/user/bin/script" whatever. Any arguments appear as "$1", "$2", "$3" and so on. The count of arguments is in the shell variable "$#".

Common ways of dealing with this involve shell commands getopt and shift. getopt is a lot like the C getopt() library function. shift moves the value of $2 to $1, $3 to $2, and so on. $# gets decremented. Code ends up looking at the value of $1, doing things using a case-esac to decide on an action, and then doing a shift to move $0 to the next argument. It only ever has to examine $0, and maybe $#.

The shell command and any arguments to that command appear as numbered shell variables: $0 has the string value of the command itself, something like script, ./script, /home/user/bin/script or whatever. Any arguments appear as "$1", "$2", "$3" and so on. The count of arguments is in the shell variable "$#".

Common ways of dealing with this involve shell commands getopts and shift. getopts is a lot like the C getopt() library function. shift moves the value of $2 to $1, $3 to $2, and so on; $# gets decremented. Code ends up looking at the value of "$1", doing things using a caseesac to decide on an action, and then doing a shift to move $1 to the next argument. It only ever has to examine $1, and maybe $#.

Clarify that such code only looks at $0: shift moves $1 to $0.
Source Link
user732
user732
Loading
Source Link
user732
user732
Loading