how to create installer of sh file in ubuntu - shell

i m creating one application on ubuntu server in shell script. I write one shell script which runs other perl scripts. i want .exe file of that .sh file

You're just trying to write a shell script. In that case you just need to create the .sh file you want to be executable and then write your shell script as follows (the #!/bin/sh indicates which interpreter to use)
#!/bin/sh
... shell commands ...
then do a
chmod +x myscript.sh
to make it executable. Then to run it you perform a
./myscript.sh

If you want to have you application installed via yum, you should package it as an rpm, put it in a public repository and then make it available to your users.

Related

Having issues executing a makefile (run.sh) in git bash

I am trying to use git bash to run my .sh file that was generated using Makefile.
When running the command ./run.sh I get this message ./run.sh: line 1: /home/user/run: No such file or directory
To run a script file (using Git Bash), you do the following:
Add a "sh-bang" line on the first line (e.g. #!/bin/bash OR #!/usr/bin/env sh) this is how git bash knows a file is executable.
Use ./ (or any valid dir spec): ./script.sh
Note : any "sh-bang" will work
You are using git bash so I suppose you are using Windows.
As for me I always use shebang on my scripts. Depending on the content of your script, you may add one of the following lines at the first line of your script.
#!/bin/sh
#!/bin/bash
#!/usr/bin/perl
#!/usr/bin/tcl
#!/bin/sed
#!/usr/awk
#!/usr/bin/python
If you still have problems running the script with ./run.sh command, you may try to use sh run.sh (on Git bash) and it should execute the script just as ./run.sh does it on linux.
This error message says that the first line of the script tries to execute an executable program named run in your home directory, and this does not exist.
I don't know what run.sh is supposed to do, but if you want to execute it a program, you need to make sure that the program exists, for instance by creating it.

How do I create new unix executable (.sh?) files for the terminal to use as commands?

I'd like to make some files to put in my /usr/bin folder (Mac OS) and be able to run them by typing the name to the terminal, like the commands gcc, cd, or vim (those are all in that folder). When I open such a file as text, it appears encrypted, so I'm not sure how to create one or what extension to use. Thank you.
The files you see in /usr/bin are not encrypted - they're compiled code in machine language different from bash scripts. You can however have scripts also in the /usr/bin location and have them run exactly as you are expecting.
In order to do that, you will have to create an executable script file. In unix, scripts are not identified by file extension but by 2 things:
executable bit set on the file permission level
Script interpreter header, such as #!/bin/bash
For a bash script, you can do the following:
Make a new file with the following content:
#!/bin/bash
echo "Hello world - My first bash script."
Save the file as hello.sh (the .sh is just convention, it could be any file name).
Then run chmod +x hello.sh and you will be able to run this file as an executable.
Move this file to /usr/local/bin and you should be able to run hello.sh from command line and it should execute your program.
You can create scripts, for example in bash, make the file executable with chmod and put the file path in your $PATH.
Example:
Create a new file called myscript.sh, you can use vi or any editor you prefer.
Add the content below on it:
#!/bin/bash
echo "Hello world!"
Now make it executable:
chmod u+x my script.sh
You can run your script like this ./myscript.sh or add it to your path:
export PATH=$PATH:$PWD
Now you can just run with the name, like myscript.sh
Programs such as gcc and cd are not encrypted, but compiled; however, if you create a shell script (without .sh as suffix; the .sh file extension for a shell script is optional) and place it in /usr/bin or any PATH location, and you chmod +x <script-path> (to give execute permission) then you can directly use that as a command.
Note: use shebang to mention the script interpreter, e.g. #!/usr/bin/env bash or equivalent for korn shell, python, etc.

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.

Run a bash script in cygwin using ./

I have a simple bash script that throw errors on a Windows machine in the Cygwin xterm terminal when I call it like so: ./myscript.bat. It runs fine when I call it like this: /cygdrive/c/cygwin/bin/bash.exe myscript.bat. I am thinking that my shell is not using bash by default. How can I set it to bash so that the next time I open the shell, I can execute my script using ./myscript.bat?
When you execute a file, Windows (or some component within Windows) decides how to execute it based on the extension part of the file name.
Cygwin inherits this functionality, letting you run Windows commands from within Cygwin. Cygwin also implements most of the usual UNIX functionality (running commands based on their content), but the combination of UNIX and Windows semantics can't always be perfectly clean.
The .bat suffix refers to a Windows batch file, so when you try to execute myscript.bat, the system treats it that way rather than as a bash script.
Change the file name from myscript.bat to myscript.bash or myscript.sh -- or just drop the extension altogether (since someone running your script shouldn't need to care how it's written).
There are several other filename extensions you should avoid (like .cmd), depending on how Windows is configured. A few quick experiments show that a .sh extension is safe, but really you don't need to use an extension at all for a shell script.
And, as R Sahu's answer says, you also need to make sure the script has execute permission if you haven't already done so:
mv myscript.bat myscript
chmod +x myscript
You'll probably need to change permissions of the file to make it an executable.
Try
chmod +x myscript.bat
./myscript.bat

Converting a shell script to a dmg

I have a shell script with some functionalities. I want to convert it to an executable file. Any idea if this is possible?
Thanks
Add the following line at the very top of your script:
#!/bin/sh
This is known as a shebang. It indicates which program to invoke the shell script with when you execute it. You could change it to anything. Eg, to run a zsh script you would use #!/bin/zsh, which is the path to the zsh interpreter on my machine.
Then you need to mark the file as executable using chmod. You can do this as follows:
chmod +x myscript
You can now run the script like this:
/full/path/to/myscript
Or, if you're in the directory the script is in:
./myscript
The '.' expands to the path of your current working directory.
If you want to be able to run the script from anywhere, stick it somewhere in your path. Eg.
mv myscript /usr/bin
You can now run the script from anywhere by typing in just the name.

Resources