shift
noun
say it: “SHIFT” /ˈʃɪft/
A bash command that drops the first argument, so the second becomes the first and the count goes down by one.
What does shift do in bash?
shift drops the first argument, and the rest move down one, like a line at a counter moving up: $2 becomes $1, and $# goes down by one. A script with subcommands uses it to drop the command's word before handing the rest on.
words() {
echo "$# words, the first is $1"
shift
echo "$# words, the first is $1"
}
words list -c dinner
# 3 words, the first is list
# 2 words, the first is -c
In a sentence
- “After shift, $1 was -c instead of list.”
- “The recipes script uses shift to hand cmd_list only its own options.”
Level: Journeyman · More Unix terms at this level
Updated