You are not logged in.
Pages: 1
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
"read VAR" command will save the read value in the variable called $VAR.
Offline
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 )
Offline
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
What do you mean by "permanently". I don't understand what it is that you're trying to do...
Offline
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
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
Ok, that is all I wanted to know. Thank you.
Archi686 User | Old Screenshots | Old .Configs
Vi veri universum vivus vici.
Offline
You can't save something inside the script itself, but you can save it to a separate file [...]
Where's the difference?
Offline
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
Changed topic to be more relevant to actual discussion.
Offline
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
Pages: 1