PDA

View Full Version : Can someone help me with this simple shell script?



Legendary_Bibo
July 5th, 2010, 12:32 PM
I'm trying to make a shell script that will run in the terminal that will display the sudo apt-get install line so that I just have to type in the name of the application or whatever. Here's what I have, basically I just want it to display the text and put my cursor at the end of it so all I have to do is type the package name.



#!/bin/sh

echo "sudo apt-get install "
read -p

Legendary_Bibo
July 5th, 2010, 12:42 PM
I guess a better example to explain what I'm talking about. So let's say I make a desktop launcher that executes this shell script, basically all I want it to do is display



sudo apt-get install [] <-- this is where my cursor would be


so then all I would have to do is type in the package name. I know it's simple, but I just it would be the whole echo the command and it would work, but I forgot the terminal closes automatically. I just want a shell script to display the text.

Tibuda
July 5th, 2010, 12:45 PM
#!/bin/bash
echo -n "sudo apt-get install "
read PKG
sudo apt-get install $PKG

DaithiF
July 5th, 2010, 12:47 PM
read -p "sudo apt-get install " packages
sudo apt-get install $packages

if your aim is to reduce the typing required, an alias in your .bashrc file would be an alternative, eg:

alias install="sudo apt-get install"
then you could just do:

install package1 package2

Legendary_Bibo
July 5th, 2010, 12:52 PM
#!/bin/bash
echo -n "sudo apt-get install "
read PKG
sudo apt-get install $PKG

exactly what I was going for. :D

betrunkenaffe
July 5th, 2010, 04:04 PM
read -p "sudo apt-get install " packages
sudo apt-get install $packages

if your aim is to reduce the typing required, an alias in your .bashrc file would be an alternative, eg:

alias install="sudo apt-get install"
then you could just do:

install package1 package2

but he still has to type install!

lkjoel
July 5th, 2010, 08:47 PM
I'm trying to make a shell script that will run in the terminal that will display the sudo apt-get install line so that I just have to type in the name of the application or whatever. Here's what I have, basically I just want it to display the text and put my cursor at the end of it so all I have to do is type the package name.



#!/bin/sh

echo "sudo apt-get install "
read -p

Ok, try this:

echo -n "sudo apt-get install "
read installline
# you want to install the package right?
sudo apt-get update
sudo apt-get install $installline