[SOLVED] Converting a Linux script to a desktop launcher
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I wish to convert the following alias 'tel' or its associated script to a desktop launcher. When I run this alias from the terminal, it always works. I find that most terminal commands would work in a launcher file but not 'bash'.
If I write Command=bash ~/info1.sh and try to run this .desktop file, I get a runtime error 'There was an error launching this application.' I feel that I am not going about this matter the right way. Any help will be much appreciated.
Julianvb
1. File info1.txt consists of just the following lines.
Quote:
#! /bin/sh
echo "Pls enter name whose phone number you need."
read name
grep -i $name ~/fones.txt
exit
2. I define alias 'tel' in my .bash_aliases file as follows:
Quote:
alias tel='bash ~/info1.txt'
3. File fones.txt just consists of lines with names and associated phone numbers.
you probably ask for something like:
xterm -e script_name
if you want to add a desktop-launcher for a script.
Other terminals have a simimilar solution. do "man your_terminal" and search for -e.
I am not that sure if an alias will work with that, it usually is used for the shell, and doesn't do that much(functions might work instead, not sure either, but: ).
Just put the script in ~/bin and use that., make the desktop-launcher use "whichever-terminal -e scriptname" to launch it.
A few things, just saying them, nothing is written in stone:
info1.text is used for both, the scriptname and the file you grep. (?).
There is no need to add an extension to a shell script., like .txt. Call it grep_fones or such, without extension.
Quote the expansion of variables, so "$name", not $name.
No need for "exit".
#!/bin/sh is not bash, so if you want bash make the shebang use bash, probably #!/bin/bash in your case.
uhm. i think the terminal will exit as soon the script finishes. You will need a solution to not close before you have seen the output. Ask the user for further input via read before the script "exits", or such.
#!/bin/bash
read -p "Name please " name
grep -i $name list
echo;echo "q to quit"
read g
[[ "$g" = 'q' ]] && exit
you will need to add that so it keeps your terminal open so you can reference whatever number you are looking up, else, it will just grep then exit, closing your terminal.
Honestly I wasn't aware of the fine points about Bash. I copied the old shebang from some place long ago when I first started writing scripts. Since they all seemed to work, I moved on ignorantly. My info1 file normally appears as info1.txt in my .bash_aliases file and in my 'tel' alias. I renamed it only tonight but it still works as far my alias 'tel' or the execution of the info1 script goes.
Thank you all very much for your suggestions and sharing your extensive knowledge with me. My Linux Mint system has both xterm and uxterm. When I run the following, the script quits prematurely after I enter an input to it.
Code:
xterm -e info1.sh
whereas
Code:
bash info1.sh
always responds with the proper output after I enter an input to it.
Thank you very much for sharing your extensive knowledge with me. My Linux Mint system has both xterm and uxterm. When I run the following, the script quits prematurely after I enter an input to it.
Code:
xterm -e info1.sh
whereas
Code:
bash info1.sh
always responds with the proper output after I enter an input to it.
Quote:
Originally Posted by nodir View Post
yup, of course. I probably wanted to say "may not be bash ".
Thanks for making it more clear.
most of what i said after "not written in stone" is just a sidenote.
he will get away with it, as far i can see.
No worries. It was a minor quibble on my part
BW-userx,
I am kind of dense. I read Reply #6 and still fail to grasp its gist. Please help me. Clearly you folks are much younger and sharper than I'm. I regret to admit it; time has a way of pushing me toward 90.
I am kind of dense. I read Reply #6 and still fail to grasp its gist. Please help me. Clearly you folks are much younger and sharper than I'm. I regret to admit it; time has a way of pushing me toward 90.
Julianvb
if you use the methoid of calling a terminal to execute your script, as soon as it is completed, as you've seen it exit the terminal, thus you cannot read the ph number, the script above it prevents the terminal from exiting until the user enters the retuired q for quit.
'read' holds the terminal open until something is entered. Everything after xterm is just telling xterm what size, font color -fg and background color -bg , T is for title, -e is command to execute.
this is just another methoid of doing what you're asking to do.
#!/bin/bash
read -p "Name please " name
grep -i $name list
echo;echo "q to quit"
read g
[[ "$g" = 'q' ]] && exit
BW-userx,
Thank you so much for your great help. I've just implemented your much better version of my info1 script and it works just like my original one. Of course, your is more elegant. You may regard my primitive script a quick and dirty one even though it always works OK.
My basic question is 'How does one write a desktop launcher version of a Bash script step by step ?" I hope you'll bear with my slow wit.
1. File info1.txt consists of just the following lines.
Quote:
#! /bin/sh
echo "Pls enter name whose phone number you need."
read name
grep -i $name ~/fones.txt
read
2. I define alias 'tel' in my .bash_aliases file as follows:
Quote:
alias tel='bash ~/info1.txt'
3. File fones.txt just consists of lines with names and associated phone numbers.
Hi, Everyone,
In order to make my script info1.sh work with the Desktop instead of the terminal only, I simply replaced 'exit' with 'read' as the final command in the file to keep the screen open. Linux Mint does not care whether $name is double-quoted or not and accepts the shebanq #! /bin/sh and #! /bin/bash for bash scripts according to my experience. You may call me dumb-lucky or a lucky dummy.
The following is my working desktop launcher file:
Finally I beg you all to forgive me for being so sloppy and inelegant as I cannot afford the luxury to strive for purity. I am a retired electrical engineer, software and hardware. Pragmatism is my life-long religion. However, I bear no ill will toward purists. The world is vast enough to embrace both purists and pragmatists.
In order to make my script info1.sh work with the Desktop instead of the terminal only, I simply replaced 'exit' with 'read' as the final command in the file to keep the screen open. Linux Mint does not care whether $name is double-quoted or not and accepts the shebanq #! /bin/sh and #! /bin/bash for bash scripts according to my experience. You may call me dumb-lucky or a lucky dummy.
The following is my working desktop launcher file:
Finally I beg you all to forgive me for being so sloppy and inelegant as I cannot afford the luxury to strive for purity. I am a retired electrical engineer, software and hardware. Pragmatism is my life-long religion. However, I bear no ill will toward purists. The world is vast enough to embrace both purists and pragmatists.
Julianvb
so its working?
if you are just issuing commands in a electronic piece of paper, or e-paper as I call it sometimes. You don't need a shebang because it is not bash it is just a file made executable to issue commands in what is called a wrapper.
I've got one that inside the file it is just simply
Code:
/media/data1/scripts/resamplemp3s
the name of that file is called resamplemp3,
and it is placed in my /usr/local/bin. So all I have to do is open a terminal and type, resamplemp3. That cuts down on typing. Removing the need to type in the absolute path and script name, or changing in to the dir then typing ./resamplemp3s
just remember to make it executable
Code:
chmod +x filename
now all I have to do is type resamplemp3 and it starts the script.
all of this works wihtout a shebang
Code:
echo "bob"
mkdir deleteme
well="go back before its too late"
echo $well
#chop it off
what=${well#*before}
echo $what
read -p "give me a value " value
if [[ $value = "no" ]] ; then
echo "why not?"
else
echo $value
fi
Finally I beg you all to forgive me for being so sloppy and inelegant as I cannot afford the luxury to strive for purity.
I am not at a scripting level where i could evaluate others, not even close, but to me:
you neither have been outstanding sloppy nor inelegant, and sure not outstanding slow.
I hardly add scripts as desktop-launchers, but when i did, it sure confused the heck out of me and took me longer to get it sorted (as said: you might say i am slow and got no talent ... :-) ).
to give one example: many people don't quote variable expansion, some as they don't know any better, some as it is not always strictly needed.
Perhaps i didn't say it clear enough, but my main info was "termina-emulator -e", and the rest was just "into the bargain" (as i see now: perhaps confusing, superfluous).
I hesitated quite a bit,
as you didn't ask for it, none of it was standing in your way to solve the question you have stated very clearly in your first post.
Short version: to me you are doing fine. Solving the stuff as you run in them.
To add something useful too: For the future you might want to sure https://shellcheck.net
(assuming you will run in problems which might relate to those fine details as the used shebang. They might not relate to it, but at least you can exclude it with shellcheck). I guess i always prefer asking in a forum or irc channel, as i get better explanations and extra-info ... but it is a good tool.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.