0

I'm a bit confused, so I looked it up, and I found this:

FILE1=$1
wc $FILE1 

this is a bit confusing to me, what does assigning the variable expression operator, followed by the number 1 to FILE1, but FILE1 is just a variable, and we're assigning what? The number 1 to the variable expression operator?

How does this work exactly?

What can I do to better understand this concept?

2
  • How does that make FILE1 a file to be passed onto the script?
    – The_Senate
    Oct 22, 2018 at 1:12
  • $1 is the first of the "positional parameters" to a script / program / function, explained in your shell's man page.
    – RudiC
    Oct 22, 2018 at 10:18

1 Answer 1

1

$1 is a variable containing the value of the first argument passed to the script, so if one ran

./myscript myfile

then $FILE1 would be set to myfile

3
  • what if I named it something else? ./626 myfile ?
    – The_Senate
    Oct 22, 2018 at 1:13
  • Also, is myfile a command in the bash script?
    – The_Senate
    Oct 22, 2018 at 1:13
  • myfile is an argument, much like you would pass -l to the ls command. It can be an arbitrary string that you can use for whatever purpose in your script. $1 references the first argument that comes after calling your script. Oct 22, 2018 at 1:20

Not the answer you're looking for? Browse other questions tagged .