If a script is called with ./myscript.sh arg1 arg2 arg3, what does $2 represent?

  • The total number of arguments passed to the script.
  • The name of the script itself (myscript.sh).
  • The second argument, which is "arg2".
  • The process ID of the script.
In the given example, $2 represents the second argument passed to the script, which is "arg2". It's important to note that in shell scripting, arguments are accessed using positional parameters like $1, $2, $3, and so on.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *