How to put a command in a SH file - bash

I'm using wine to open a game and to open the game I must enter the following command in the terminal
cd "/home/brandon/.wine/dosdevices/c:/Program Files/League of Legends/RADS/system"
Then I enter this below
WINEDEBUG=+ntdll wine "rads_user_kernel.exe" run lol_launcher $(ls ../projects/lol_launcher/releases/) LoLLauncher.exe
and then the game normally loads.
Is it possible to put the 1st command and the 2nd command together in an .sh file so I just double click it and everything will be automatic?

#!/bin/bash
cd "/home/brandon/.wine/dosdevices/c:/Program Files/League of Legends/RADS/system"
WINEDEBUG=+ntdll wine "rads_user_kernel.exe" run lol_launcher $(ls ../projects/lol_launcher/releases/) LoLLauncher.exe
If I understand your problem correctly, this should run the two commands through the script.
You also will have to do
chmod u+x name_of_script
before you can run it.

Related

Is there a way to launch Terminal with a prefilled statement?

I want to open a terminal window with a statement. Is there a process I can run that will do this?
For example, I want to run a script that 1. Opens Terminal and 2. has the following statement:
java -version
The user then can press the Enter key to run the statement
One way to do this is by wrapping the command in a .command file that contains a command to read something, such as:
#!/bin/bash
command="java -version"
echo $command
read input
exec $command
...then, make the script file executable by running chmod +x filename.command on the file that you put this in, and run it (e.g. from the Finder or by using open filename.command). This should launch the terminal, print the command, and wait for the user to press Enter before running it.
You will note that since this is a script, you can customize any of the steps above to do whatever you want, e.g. printing more stuff or running other commands.

How can I make my shell script executable

I wrote a shell script which opens some directories and runs some script, I run this bash file by terminal (bash filename.sh), how can I make it clickable?
You need to add the following shebang line to the top of your code.
#!/bin/bash
You also need to ensure that the script has executable permissions by running:
chmod a+x <filename>.sh
You first need to start your script with
'#!/bin/bash '
and save it as <filename>.sh Also make sure that you keep the permissions as a+x i.e all users can execute the script.

Ubuntu desktop script to open terminal, navigate to a folder and run compass watch

I have tried to search for a simple answer for running a simple script (myscript.sh) from the Ubuntu (13) desktop that would open the terminal, navigate to a folder (/var/www/myproject) and then run the "compass watch" command (and then stay open). First I thought this would be very simple to accomplish, but after several fails and searches, this particular task/script seems overwhelmingly hard to get to work.
To do this manually is not a big task:
Open terminal
navigate "cd /var/www/myproject"
run "compass watch"
I thought this would be a walk in the park (although I am quite new to terminal and scripting), but through the searches I got some weird desktop launcher answers and complicated bash scripting functions solutions for sub-shell work-a-rounds. My question is, can this be done with one single (simple) file that is launched from the desktop?
Either you make a shell script (.sh file, don't forget to make it executable) or you make a desktop file (.desktop). Either of those can be double-clicked, although the former might bring up a dialog asking whether you want to execute it (can be configured, but only per user, IIRC).
myscript.desktop:
[Desktop Entry]
Exec=bash -c 'cd /var/www/myproject && compass watch'
Name=myscript
Terminal=true
Type=Application
(Note the Terminal=true part.)
myscript.sh:
#!/bin/sh
gnome-terminal -e 'cd /var/www/myproject && compass watch'
(Assuming you want to use GNOME Terminal.)
Of course, there are numerous other options.
I didn't get well where is your problem ...
If you want to run a script like that (double clic) you should first make it executable:
chmod u+x myscript.sh
Then you just have to place a link to this script on your desktop (or the script itself if you want ...)
When double-clicking it, you will have the possibility to run it in a terminal.
Then put whatever you want in your script ( the navigate "cd /var/www/myproject" , run "compass watch" part) and end the script (myScript.sh) file with $SHELL to keep the terminal open after the script execution (:

How to create and run a bash file?

How to create a bash file?
I found following bash script.
#!/bin/bash
for f in *.wav; do
echo "Processing $f file..."
afconvert -f caff -d LEI16#44100 -c 1 "$f" "${f/wav/caf}"
done
I have Mac and Windows.
But I don't know where I have to put this and how I can run this script?
Just save the text into a file called my_bash_script a file, make it executable and run it from the command line like this:
chmod u+x my_bash_script
./my_bash_script
Judging by the file it will need to be in a directory containing *.wav files.
As you have two different OS setup, I will split my answer in two parts.
First: Windows
Windows does not have a Bash interpreter, nor the afconvert program the code above is trying tu run. Your best bet will be to use Cygwin to install a Unix console on your Windows. Also I don't know, where you could get afconvert from.
OSX
OSX does have a console and the afconvert software (at least my OSX does). You can simply drop the file in a folder and give it a name ending in .sh. Then you should be able to run it.
Just paste the text into a plaint text file and then mark it as executable:
chmod +x yourScript
To run it:
./yourScript
Place the script anywhere you have your .wav files. When fallow instructions given here:
http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_02_01.html#sect_02_01_03

terminal sudo command

I'm a complete novice at this (terminal in Mac leopard) and hoping to get an lifeline from the web as I've certainly hit a wall.
I want to run a script as a root in terminal. The script is saved as a text file with a .rtf extension. I've inserted into terminal:
sudo filename.rtf
then I get asked a password which I've typed in (admin password) and pressed enter; then it shows a prompt: sudo: Mac: command not found
I've tried it with the extension hidden but got the same result. Any pointers on what I'm doing wrong?
Thanks in advance
You need to first get the script out of the .rtf file and into a plain text file (open it up in TextEdit and select "Make Plain Text" from the format menu, then save it again as myscript.sh).
Now you can type
sudo sh myscript.sh
The "magic" sh letters there are because as another responder says, sudo will temporarily elevate you to superuser and run a program. In *nix environments, that would be anything with the executable bit set, meaning that someone's explicitly told the operating system that it's safe to run a file. In your case, your myscript.sh has not been "blessed" in this way, so to run it you need to feed it into a program that knows how to understand it. That program is sh, and it does have the executable bit set. Thinking of it as sudo (sh myscript.sh) might make it a bit clearer.
If you plan on running this script a lot, you might want to actually make it executable on its own. This amounts to putting special instructions inside the file that tell the operating system how the file should be run. If you stick #!/bin/sh (this is called a shebang line and tells the OS what to do with your file) on the first line of your script, and then type chmod u+x myscript.sh (this tells the OS that you, and only you, are allowed to execute your file), you'll be able to run the file directly with sudo myscript.sh.
sudo is used to execute commands as the root user of the machine.
when you type
sudo [somthing]
the shell grants temporary root privilges and then executes the given "somthing"
assume your script is in bash, you should have done
sudo sh filename.rtf
Also, it's better to save script as plain txt, with an sh extension, so you would execute
sudo sh myscript.sh
first set the script as executable:
chmod +x filename.rtf
Then you can run it like so:
sudo ./filename.rtf

Resources