Your Location is: Home > Linux

Linux bash get an input on the same line as execution? [duplicate]

From: Iran View: 2693 throwaway 

Question

I made a .sh file with a program, the current input is as follows:

$ ./myprogram.sh
file.txt

How can I make it so the input is as follows instead:

$ ./myprogram.sh file.txt

Best answer

Inside the shell script, you can refer to the arguments by their positions as $1, $2, etc. Note that the arguments start at 1, and $0 is the name of the executed script. $# contains the total number of arguments.