Command In Terminal Versus In Panel Launcher [Mostly Resolved With Great Help]

Hi
I am having an issue with the following command. It works fine if I launch it in a terminal window.
Can copy and paste / launch it multiple times in a row and works great. In OBS Studio it deletes the obs-studio from current project (contains the assets) and replaces it with a blank start up with all my initial start up settings. Also if I want to work on an existing project I just have to copy it's backed up file to the Reset folder (Reset folder contains copy of initial clean start up) and use the reset command.

The Reset Command:

rm -rf /home/mendy/.config/obs-studio && cp /home/mendy/OBS_Studio/Reset/obs-studio -r /home/mendy/.config

Now when I create a launcher of Type Application In Terminal and paste the command and launch it, it then deletes the data in the Reset folder and trashes my .config file (not issue as it's backed up)
Am I doing something wrong in creating the Launcher?

Then other question is if can get the panel launcher working is there a way to make it need a double click like if the launcher is on the Desktop. Reason it would be next to OBS in panel and if accidentally hit it would launch with no question, versus double click on Desktop launcher. Maybe a yes/no option?

Thanks

An opening stab: I think, especially for a complex command such as that, you would be better creating a script in /home//bin. Name it reset.sh maybe? First line would be #!/bin/bash then each of your commands on successive lines.

Be sure to mark the file executable

Then put /home//bin/reset.sh as the command in your launcher create sequence.

I wonder if you're dealing with some difference in environment between the two methods, or a line length issue in the launcher.

The create a launcher mechanism creates a text file .desktop in various places /home//.config/.../.../launchers depending on if it is a panel launcher or a default or a plank.

Not sure it will help, but it is what I would try.

Also, the syntax on the cp command looks odd with the option -r not immediately after the cp. Maybe it runs fine, or maybe there is a different behaviour I don't know about.

1 Like

You are correct after many iterations got the -r on wrong end but it doesn't affect its operation. Corrected and still operates the same.

rm -rf /home/mendy/.config/obs-studio && cp -r /home/mendy/OBS_Studio/Reset/obs-studio /home/mendy/.config

Created separate launchers for each function and they work. Combining into one fails, ended up adding two launchers temporarily till I have more time to investigate the script method you mentioned. Also substitued ; in place of && with no change.
Still looking for possible y/n on press.
Will check back with you after figuring out script. Took a bit to get to where I am at, found issue I had OBS Studio and finally figured out needed to have an underscore, didn't like the space. Major issue for me is major GUI guy
dipping toes into unfamiliar area. :grinning:
What term would I need to search for a y/n type question before executing the script. IE: press launcher and have it ask do you want to do this action.
rc
Image R is remove and C is copy operation.

My apologies, I won't be a lot of help until Monday--the only internet available at my home is on a cell phone with intermittent coverage.

For y/n input search for "bash script y/n" and you will find numerous examples.

I know of no way to do that in a single command suitable for a launcher. You could search for "one-liner bash command y/n" and that might turn something. Stackexchange website unix/Linux is a good place to hunt for that kind of thing.

I can dig out more if needed on Monday, but maybe that will help you out.

Hi Mendy,

You wrote:

rm -rf /home/mendy/.config/obs-studio && cp /home/mendy/OBS_Studio/Reset/obs-studio -r /home/mendy/.config

Now when I create a launcher of Type Application In Terminal and paste the command and launch it, it then deletes the data in the Reset folder and trashes my .config file (not issue as it's backed up)
Am I doing something wrong in creating the Launcher?

Yes , but understandably so.
Launchers run the application directly i.e. without a shell, that means there is no bash to interpret your command. For instance, the "&&" shellcommand will not be recognized as a command and will be passed as argument to 'rf', just like everything that follows.

I didn't test this but i guess that the 'exec=' line in your launcher gets interpreted as:

  1. delete old config directory
  2. delete '&&' (which doesn't exist as a file ofcourse)
  3. delete 'cp' (which can't be found in the working directory)
  4. delete the 'Reset config' directory
  5. interpret '-r' (again, so ignored)
  6. delete the users config directory (including configs of all other applications)

What you probably need to do within the .desktop file is to invoke bash yourself, with your command as argument, like this:

exec=bash -c "yad && rm -rf /home/mendy/.config/obs-studio && cp -r /home/mendy/OBS_Studio/Reset/obs-studio /home/mendy/.config"

The addition of 'yad' is the yes/no option you asked for

Again, I did not test this but I guess this will work :slight_smile:

1 Like

Hi thanks to both will continue exploring but it will take time. I think bash is going to be too much for me to comprehend, using two buttons works at moment. (actually hate to admit how long it took me to figure out the cp and rm commands for my purpose) @tkn it actually ended up clearing all but one folder in the .config directory and deleted the data in the Reset directory. Did try script but errors. Then changed to delete just a directory on the Desktop. Still failed. Had a Caja crash the other day which removed my panels, had to do CAD reboot. Days before had backed up mate panel and Mate Tweak changed panel and went back to my custom panel. Bottom was borked but had backed up about a week before by dragging the launchers into backup folder, rename ones with odd names. Then just opened Calc sheet with order and dragged from backup to bottom panel (49). All is well now. Need a break for now. :grinning:

Back again. Had some time to do some research and to me seems like similar to .bat files in another OS. :grinning: Initially at start of project found I could not just copy and overwrite the directory as happens with copying a file and it overwrites it. Recent checking seems to confirm this. Worked on these two scripts and both work from terminal but not from launchers. Tried some simple ones and could not yet get them to work in launchers. So will pass for now on that aspect. Did end up creating a My_Scripts folder in my home folder and reseached how to add it to PATH so saves a lot of time not having to type out various paths. Making progress. Images are present status.
Thanks again to @charles-nix and @tkn for suggestions on possible solution.


Similar to .bat files? Well, yes, if you consider that a bicycle is similar to an F-35 :slight_smile:

All unix shells are vastly more powerful than .bat. The most common shell for Linux, bash, is extremely powerful, including system level utilities and a full programming language.

Now, I'm no bash expert, but it is usual form to put a "shebang" at the top of the script. Linux determines nothing from extensions on a filename. This first line tells which (of the many) interpreters should be used to execute the script. For the most common shell scripts the line will be "#!/bin/bash"

That could be what is missing in your launcher difference. As @tkn notes, "launchers run the command directly". So when the launcher hits your script, which shell interpreter (among dozens) is it supposed to choose? The commands you are using in the script and the syntax will be different for other interpreters. (bash,sh,zsh,csh,perl,python,et al.)

Using MyScripts is perfectly fine. The Linux/Unix standard name would be "bin", short for binary, meaning executable programs. For your personal programs, it would be /home//bin. None of that is at all required, but just in case you were wondering :wink:

1 Like

@mendy .
If you have any bash questions: just ask.
I am a bit of a seasoned bash-a-holic
and I know that there are some other people here that are at least equally proficient :slight_smile:

b.t.w. the 'Y/y' and 'N/n' in your case statement should be 'Y|y' and 'N|n' respectively.

Did a lot of testing and even though things I have read saying it is not needed, in some tests it worked fine and failed in other tests. Set up simple tests and double clicked script and open in terminal to test. Once running there created launcher and operator error was blindly entering command versus browsing to script location and selecting it. After a bit cleaned up both scripts and they now work as launchers in bottom panel. Took some time to create the script below for you. :grinning: Got in some Inkscape time.

I was looking into | and think it is a command and the Y/y ties into the select command and something called words. Did not find definitive info on this. Found one example where | is used to automaticall enter Y with no confirmation. (yes |rm *) I could be wrong. Wouldn't be the first or last time.

Edit: Added working scripts

No worries, you got everything almost correct :slight_smile:

Here is some relevant info:

'|' a.k.a. the pipe symbol is an overloaded operator in bash.

Between commands it functions as a 'pipe' i.e. a command that takes the output from the previous command and feeds it to the next command
like this:

yes | rm -i *

But within the context of a 'case' statement it functions as a logical "OR".

like this:

case "$yn" in
Y|y ) someting ;;
N|n ) otherthing ;;
esac

It could be that by sheer luck '/' also works but that is actually unspecified.
(in that case, yours is a pretty remarkable discovery :slight_smile: )
Definite info about the case statement can be found by typing help case at the commandprompt.
Or man bash for the complete bash manual (warning: the bash manual is pretty extensive).

Good documentation is found here (but i am afraid it is not really a fun way to learn bash, YMMV):
https://tldp.org/LDP/Bash-Beginners-Guide/html/Bash-Beginners-Guide.html

What I used when starting bash, and which helped me tremendously, was this
(although a lot of people say that it is absolutely not advisable, I still recommend it):
https://linux.die.net/abs-guide/
It brought me up to speed within a few days and after that I started a pretty big project in bash for server use (which really honed my skills).

I have to confess at this point: I was already somewhat proficient in C so I might have had a bit of an advantage when learning this.

b.t.w. That bike-picture in pluma is way cool :slight_smile:

2 Likes

Oh b.t.w. The shebang line:

A script without the shebang line is at the mercy of the program that invoked it:
If the parent process is bash, the script is read and executed as a bash script.

So yeah, it works most of the time.

If the parent process is dash (debian almquist shell), the script is executed as a dash script.
It will run, but fail on bash specific (non-posix) commands.

Same for ksh zsh csh etc

If the parent process is some other process, it will probably fail completely.

With the #!/bin/bash line you specifically ask the kernel to invoke the bash interpreter so you will be assured that it will execute your bash-conform script to the letter, independent from the capabilities of the parent process.

I hope this sheds some light on this subject and explains some random experienced 'WTF' moments :slight_smile:

EDIT: corrected a pretty dumb typo, sorry for that.

2 Likes