Instead of reading input from users, you can also pass arguments to a bash script. For example, let's create a bash script named size2.sh that does the same thing as the script size.sh, but instead of reading the file from the user, we will pass it to the script size2.sh as an argument:
elliot@ubuntu-linux:~$ cat size2.sh
#!/bin/bash
filesize=$(du -bs $1| cut -f1)
echo "The file size is $filesize bytes"
Now let's make the script executable:
elliot@ubuntu-linux:~$ chmod a+x size2.sh
Finally, you can run the script:
elliot@ubuntu-linux:~$ size2.sh /home/elliot/size.sh
The file size is 128 bytes
You will get the same output as size.sh. Notice that we provided the file path
/home/elliot/size.sh as an argument to the script size2.sh.
We only used one argument in the script size2.sh, and it is referenced by $1. You can pass multiple arguments as well; let's create another script size3.sh that takes two files (two arguments) and outputs the...