Problem in making a script
Nils Kassube
kassube at gmx.net
Sat Jul 2 11:21:14 UTC 2011
Amrit Pal Pathak wrote:
> On Sat, Jul 2, 2011 at 5:07 AM, Nils Kassube <kassube at gmx.net> wrote:
> > You could extend the echo command with the rest of the text you
> > need in the line. Something like this:
> >
> > echo -n "Please enter device name: "
> > read device
> > ...
> > echo "device = /dev/$device" >> "$TEMP"
> >
> Here $TEMP is temporaily file name?
Yes. At the line "..." I omitted the creation of that temp file etc.
because I wanted to show how to use the echo command with the user input
appended to the extra text.
> Can I use here a variable then can replace $fname with
> that variable in following code.
I'm not sure what you want to ask here. Anyway, you can name a variable
whatever you want. It doesn't matter if it is "fname" or "device" or
"donaldduck". It is only important that you later use the right variable
when you write to the conf file. Of course it is much easier to
understand the code if you use a variable name which tells you something
about the designated contents. I was using "device" for clarity because
the user input was a device name. I would expect some file name in a
variable "fname" but feel free to use "fname" instead of "device".
> sudo wget http://202.164.53.116/~amritpal/edit/kannel.conf
> sudo chmod a+w kannel.conf
While these lines have nothing to do with your original question, I'll
comment on them anyway. These lines are a bit strange because first you
use sudo to wget a file, and then you change the permissions to make the
file world writeable. If you don't use sudo for the wget command, you
don't need to change the permissions afterwards. Never use sudo unless
you really know it is needed.
> echo -n "Please enter device name: "
> read device
> echo "device = /dev/$device" >> "$TEMP"
Well, that line is in the wrong place. You can't write to a temporary
file before you create it. If you have used the TEMP variable before,
you might write to the wrong file. If it wasn't used before, it would
simply be a syntax error.
> TEMP=$(mktemp)
> head -n $((29 - 1)) "kannel.conf" > "$TEMP"
> echo "$fname" >> "$TEMP"
Replace this line with the one that was in the wrong place above.
Nils
More information about the ubuntu-users
mailing list