0

I have seen one shell script starting with the below code :-

#!/bin/bash

currfoldername=$1
cd $currfoldername

can anyone describe what does $1 mean here?

Thanks for your reply!!

aquaman
  • 1,523
  • 5
  • 20
  • 39
Biman Roy
  • 7
  • 3
  • Type `man bash` in your terminal then scroll until you reach *"Positional Parameters"* under the *"PARAMETERS"* section. – axiac Nov 28 '17 at 09:26

1 Answers1

2

$1 means the first argument given while executing the shell script.

Example -

# my_script.sh
#!/bin/bash

currfoldername=$1
cd $currfoldername
echo "in $currfoldername"

execute -

./my_script.sh my_folder

output -

 # value of variable currfoldername is my_folder.
 #cd to my_folder
 in my_folder  # echo statement
aquaman
  • 1,523
  • 5
  • 20
  • 39
  • thanks, but someone told me that here $1 means whenever you call the shell script then that time you will have to pass input over here like current directory/path. Is it right explanation? – Biman Roy Nov 28 '17 at 08:00
  • That's just a really poor way of restating what this answer is telling you – tripleee Nov 28 '17 at 08:05
  • @BimanRoy Well you can also not pass any argument and still this script will run but will show unexpected behavior. – aquaman Nov 28 '17 at 08:08