Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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' ?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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 $1 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

share|improve this answer
    
thank you very much for the help :) –  user123418 Jan 3 at 21:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.