Selecting preset variables by user input in a bash script
Hello, I am writing a script to make it quicker to create desktop (.desktop) shortcuts. So far this script is only for programs found in /usr/bin (although you can right click on the shortcut and change it how you like), but eventually I will make this universal the more I learn about scripting in Linux (I can create Windows batch scripts in my sleep). I don't really need shortcuts, I just make them for my girlfriend.
My question is: What is the best method or how do I go about letting a user select a preset option and echoing that option into the file? Example: I would have set variables such as: Code:
a=Application Code:
read -p "Type of shortcut, choices are a=Application, f=Folder or l=Link:" stype Code:
echo Type=$stype >> ~/Desktop/$dsname.desktop Code:
#!/bin/bash |
Well at my own preference I'd do it to something like this:
Code:
#!/bin/bash |
I tried that and everytime I entered a name for my shortcut it just kept looping back to
Please enter a valid shortcut name. Name your shortcut, single word only:Startup Please enter a valid shortcut name. Name your shortcut, single word only:Startup Please enter a valid shortcut name. Name your shortcut, single word only:Startup etc... |
Sorry my mistake. It should be:
Code:
[[ $dsname == +([[:alnum:]_ ]) ]] |
And with that I get
Code:
Name your shortcut, single word only:Startup |
Ok here's an update:
Code:
#!/bin/bash |
This
Code:
DESKTOP_FILE=~ Code:
exec 4>~"/Desktop/$dsname.desktop" I also thought if you could also use $HOME: Code:
exec 4>"$HOME/$dsname.desktop" |
Ok that works until you get to the terminal part for true and false and then I get a loop again:
Run in terminal, true or false? false Please only enter true or false. Run in terminal, true or false? false Please only enter true or false. and also in order for the file to change from Startup.desktop to just Startup and actually execute the permissions must be changed and in my script I did this successfully with Code:
sudo chmod 777 ~/Desktop/$dsname.desktop |
Actually was just a presentation of concept so that you could get an idea about which improvements you could incorporate to your code. Feel free to do anything about it.
Anyway about the permission thing, I think it's only user that needs the write bit, so perhaps it should be just 755 if not 750 or 700. Code:
[f][F][a][A][l][L][s][S][e][E]) # should of course be [fF][aA][lL][sS][eE]) Also I don't think it's necessary to use sudo just to change the permissions. The one who executes the script is the owner of the file after all. And also, add it after closing the file Code:
exec 4>&- |
Ok I am starting to see how it's working now and will play with it to integrate it inot my script. This is totally different from any of the scripting tutorials or reference guides I've seen so I have a great deal more learning to do lol. Thanx for your help.
|
Welcome. It was a pleasure.
|
Sorry, one more thing even if I add an Exec=/usr/bin/gnome-session-properties and have set the permisions it has not removed the .desktop from being visible. The program starts up just fine though. Maybe after I reboot it may dissapear?
|
Quote:
|
All times are GMT -5. The time now is 04:35 AM. |