How can I get a variable from terminal to use it in my script?
I'm writing small programs that are allowing me to do common commands with just two or three words max like sudo apt-get update
I made it upt something like that
Now I'm trying to write a script which will allow me to install programs from terminal
the command is sudo apt-get install 'program'
I'm asking here how can I save the command 'program' in a variable to use it in my script so I can write in terminal inst 'program' ?
When you invoke a script like
myscript parameter1 parameter2
the parameter1, parameter2 etc. values from the command line are available inside the script as positional parameters $0
, $1
, ... etc
- parameter $0 contains the name by which the script was invoked (myscript)
- parameter $1 contains the value parameter1
- parameter $2 contains the value parameter2
- and so on
So in your case if you want to run your script like
inst program
to install program, then inside the script you can write
apt-get install "$1"
See for example Handling positional parameters at http://wiki.bash-hackers.org