0

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?

NermzA
  • 1
  • 2

1 Answers1

1

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"
choroba
  • 231,213
  • 25
  • 204
  • 289