My code:
#!/bin/bash for i in $@; do echo $i; done;
run script:
# ./script 1 2 3 1 2 3
So, I want to skip the first argument and get:
# ./script 1 2 3 2 3
Using arguments Inside the script, we can use the $ symbol followed by the integer to access the arguments passed. For example, $1 , $2 , and so on. The $0 will contain the script name.
A command line argument is a parameter that we can supply to our Bash script at execution. They allow a user to dynamically affect the actions your script will perform or the output it will generate.
Use the offset parameter expansion
#!/bin/bash for i in "${@:2}"; do echo $i done
$ func(){ for i in "${@:2}"; do echo "$i"; done;}; func one two three two three
Use shift
command:
FIRST_ARG="$1" shift REST_ARGS="$@"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With