You are not logged in.

#1 2008-08-24 18:49:23

haxit
Member
From: /home/haxit
Registered: 2008-03-04
Posts: 1,247
Website

Bash scripting help!!

Ok, so how do you do something that will save a inputed value, ie:

Please enter the directory:

User enters directory and the directory is saved in the script itself.

echo -n "Please enter the directory: "
read VAR

Now I want the var saved inside the script. Then the script will have a if else thing that will check that the directory exists. Do you get what I am saying?


Archi686 User | Old Screenshots | Old .Configs
Vi veri universum vivus vici.

Offline

#2 2008-08-24 18:52:46

fwojciec
Member
Registered: 2007-05-20
Posts: 1,411

Re: Bash scripting help!!

"read VAR" command will save the read value in the variable called $VAR.

Offline

#3 2008-08-24 18:54:09

Lord Illidan
Member
From: Malta
Registered: 2007-10-25
Posts: 248

Re: Bash scripting help!!

Check out this site : http://tldp.org/HOWTO/Bash-Prog-Intro-H … tml#ss10.1 Excellent resource to learn how to make bash scripts.

Also, you can use zenity to give the program a rudimentary GUI for users who are afraid of the terminal (my little sister big_smile)

Offline

#4 2008-08-24 18:59:44

haxit
Member
From: /home/haxit
Registered: 2008-03-04
Posts: 1,247
Website

Re: Bash scripting help!!

Thanks, but I want the directory to be written permenatly.

Last edited by haxit (2008-08-24 19:01:03)


Archi686 User | Old Screenshots | Old .Configs
Vi veri universum vivus vici.

Offline

#5 2008-08-24 19:09:16

fwojciec
Member
Registered: 2007-05-20
Posts: 1,411

Re: Bash scripting help!!

What do you mean by "permanently".  I don't understand what it is that you're trying to do...

Offline

#6 2008-08-24 19:18:34

haxit
Member
From: /home/haxit
Registered: 2008-03-04
Posts: 1,247
Website

Re: Bash scripting help!!

Whatever the user types in gets saved in the script as the main directory, and the user never has to input it again. I can get everythign running except for the directory to actually be written in the script. Lets say the default directory was /home/haxit and another user inputes a directory and /home/haxit gets overwritten in the script with /home/anon.


Archi686 User | Old Screenshots | Old .Configs
Vi veri universum vivus vici.

Offline

#7 2008-08-24 19:22:04

fwojciec
Member
Registered: 2007-05-20
Posts: 1,411

Re: Bash scripting help!!

You can't save something inside the script itself, but you can save it to a separate file somewhere and then have the script read that file or rewrite it when a directory changes...

Offline

#8 2008-08-24 19:31:54

haxit
Member
From: /home/haxit
Registered: 2008-03-04
Posts: 1,247
Website

Re: Bash scripting help!!

Ok, that is all I wanted to know. Thank you.


Archi686 User | Old Screenshots | Old .Configs
Vi veri universum vivus vici.

Offline

#9 2008-08-24 19:59:53

smoon
Member
Registered: 2005-08-22
Posts: 468
Website

Re: Bash scripting help!!

fwojciec wrote:

You can't save something inside the script itself, but you can save it to a separate file [...]

Where's the difference?

Offline

#10 2008-08-24 20:00:20

fwojciec
Member
Registered: 2007-05-20
Posts: 1,411

Re: Bash scripting help!!

Come to think of it, I'm actually wrong in saying that a script can't update itself -- it's only a text file after all...

Here's a rudimentary version of something like this:

#!/bin/sh
DEFAULTDIR="/home/user/tmp"
SCRIPT="/home/filip/scripts/test.sh"
echo -n "Please enter the directory: "
read NEWDIR
sed -i "s#$DEFAULTDIR#$NEWDIR#g" $SCRIPT && echo "Directory Updated" || echo "Update failed"

EDIT:
@smoon -- yeah, I don't know why I thought it was impossible...

Last edited by fwojciec (2008-08-24 20:08:18)

Offline

#11 2008-08-24 22:46:08

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: Bash scripting help!!

Changed topic to be more relevant to actual discussion.

Offline

#12 2008-08-24 23:39:40

haxit
Member
From: /home/haxit
Registered: 2008-03-04
Posts: 1,247
Website

Re: Bash scripting help!!

Thanks for the suggestion, however I got an idea for it. I will post it when I am done. Thanks for the help though.


Archi686 User | Old Screenshots | Old .Configs
Vi veri universum vivus vici.

Offline

Board footer

Powered by FluxBB