Reputation: 1
I am trying to write a shell script that takes the first word given to it as one argument and anything that comes after it as a second argument.
The user must call my shell script and provide their arguments in one line from the terminal: shellscript.sh word1 word2 word3 ...... wordn How can I write my script such that
arg1 = word1
arg2 = word2 - wordn?
Upvotes: 0
Views: 2063
Reputation: 242443
Use shift
to remove the first argument, and use "$*"
to concatenate the remaining ones.
#!/bin/bash
first=$1
shift
rest="$*" # Assuming the first character of $IFS is a space.
printf '<%s>\n' "$first" "$rest"
Upvotes: 1