Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm trying to write a script to run one of my .jar files as daemons, but I am not understanding how to create a .sh extension file in Ubuntu. I have already used vi to create a file with the code that I want, but I cannot figure out how to define the file to specifically be a .sh file. For example, I want to convert my file "foo" or "foo.txt" into "foo.sh".
Is there a simple command I am not seeing that can convert files to a .sh extension or is it a more complicated process?
Use this as a template:
#!/bin/bash
# content of your script
The first line is called a shebang and tells the OS what program that should be used executing the content of the file, in this case, bash.
To make the file executable:
chmod 755 foo.sh
To execute your script do:
./foo.sh
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
I started learning Bash on Mint Linux. The thing is I want to know how to open and execute programs. I have a test.sh in my junk directory so that I can mess around but when ever I type in gnome-open test.sh it just opens the file and not actually run it. In the test.sh file I have echo hi in there so that I can see that it worked and I gave the file the permissions for it to be an executable file so it should execute.
You need to do two things:
Give the file execution permission (+x)
Execute the file
First you give the file permission no 755:
chmod 755 test.sh
Then you start it:
./test.sh
The dotslash means "current directory", it's like saying c:\file.bat if \ is the current directory. You need that because the current dir (called PWD) is not in your PATH variable which means that you either need to specify the complete path, eg. /users/user/file.sh or using the dot which is a shortcut for the current directory.
The file permission number 755 means:
owner: 7 (read, write, exec)
group: 5 (read, exec)
other: 5 (read, exec)
If you want to be the only one to be able to even open the file you may specify 700 instead. There are plenty of combinations, but 755 is most commonly used for scripts.
edit:
I forgot to mention that you need the dotslash everytime you run the script, but you only need to issue the chmod command once for every file.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am new to Linux commands. I have a requirement where I want to start Tomcat using a shell script. The location of startup.sh file is in /usr/lib/apache-tomcat-7.0.14/bin/. Tomcat is starting using command sh startup.sh. I want to create a shell script so that it will go to that folder and will execute sh startup.sh command. How can I do this using a shell script? Can anyone share the script for doing this?
Are you serious?
#!/bin/bash
cd /usr/lib/apache-tomcat-7.0.14/bin/
sh startup.sh
#!/bin/bash
exec /usr/lib/apache-tomcat-7.0.14/bin/startup.sh
is simpler (as does not have a shell kicking around)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a file which contains key/value -pairs in the format
TAG PATH
. Now, I want to write a program that reads from the command line a TAG, and changes the current working directory of invoking bash to corresponding PATH.
How would I go about this?
You might consider something like (perhaps in your bash function)
while read tagname dirname ; do
pushd $dirname ;
dosomethingwith $tagname
popd
done < yourinputfile.txt
See this question (about read in bash) and read the advanced bash scripting guide
GNU awk might be a better tool.
Notice that you can only change the current directory of the current process using the chdir(2) syscall (invoked by cd or pushd or popd bash builtins). There is no way to change the directory of some other process (e.g. the parent or invoking one). The pushd and popd builtins also updates bash directory stack.
There is no way to change the current directory of the invoking shell (the parent process running in a terminal). But you may define your own bash function there. Read Advanced Linux Programming to understand more about Unix processes
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am trying to run a shell script on redhat linux to install an app. I am getting an error saying /usr/bin.sh: bad interpreter: no such file or directory.
In the shell script the script begins with:
#!/usr/bin/shBUILD_ID=$1.....
I am just trying to understand what the path at the begining of the line is for? Is that a directory it looks for to deploy the app?
Thanks
The first line should be #!/usr/bin/sh or #!/bin/sh if its a shell script.
If the first line are #!/usr/bin/sh then try to see if /usr/bin/sh exist and you with ls -l /usr/bin/sh
If you cant find sh then your system are in a bad stat.
The #! is a magic number that tells the kernel that the file is an excutable script.
The string immediately following the #! is the path to an interpreter that is called to read and execute the contents of the file. In the line
#!/ust/bin/shBUILD_ID=$1.....
the interpreter is /ust/bin/shBUILD_ID=$1..... The interpreter is read directly, with no shell variable substition, so it will look for a file exactly as you specified (including the equal sign, dollar, dots etc.). If the interpreter you specified is not found, a default shell issues an error message, and yours looks totally wrong. Try #!/bin/sh.
If the interpreter string is followed by a space and then some arguments, those arguments are passed to the interpeter when it is invoked.
See for example http://bash.cyberciti.biz/guide/Shebang
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
When I open a terminal, it says cannot execute the binary file and the output is something like this:
bash: /home/sandeep/bin/uname: cannot execute binary file
bash: [: =: unary operator expected
bash: /home/sandeep/bin/sed: cannot execute binary file
bash: /home/sandeep/bin/ls: cannot execute binary file
This is followed by normal prompt where everything is fine. But as a programmer it is annoying to see those many errors every time you open a terminal.
The Reason i found out is that when i installed a armeabi tool chain it created a folder called bin in the home directory and all the executables inside this directory are for arm processor. But my terminal when it is being opened it is trying to execute these arm binaries and hence it shows an error that these binaries cannot be executed(since my proc is not arm)
To solve this i can remove this folder(i tried it and it worked) but thats not the optimal solution. i want to know the script that is getting executed when i open a terminal where it is trying to execute wrong binaries at the launch.
I had a look at .bashrc but there is nothing relevant to my problem in that.
I'd debug it with strace
strace -e trace=open,read bash > output.txt
then you can check what files are getting opened when calling bash
Remove /home/sandeep/bin from $PATH environment variable.