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
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 12 months ago.
Improve this question
When I run sudo ./hello.sh form command line, it says:
: command not found
but when I explicitly type bash like :sudo bash ./hello.sh
it run successful,why?
At the first line of your Bash Script you should use shebang.
for your script shebang is like below:
#!/bin/bash
After that your script should be executable. use this command:
chomd +x hello.sh
now run your script.
sudo ./hello.sh
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
what does this command do?
!/bin/bash
My first script
clear
echo (I don't know what will come after echo , can you help me with that too?)
./hello.shell
#!/bin/bash is called the shebang (you missed the leading #).
It tells which program will execute your script.
clear is for clearing screen.
echo outputs following argument to the standard output (your terminal by default). But you must not surround your string with parenthesis as it's used for grouping command in a sub-shell. If you want to print (...), you'll have too use double quotes :
echo "(I don't know what will come after echo , can you help me with that too?)"
./hello.shell will execute your script after you gave it execute permissions with chmod +x hello.shell.
Note that commonly used extension for a shell script is .sh rather than .shell.
For more, try theses links :
http://mywiki.wooledge.org/BashGuide/
http://www.tldp.org/LDP/Bash-Beginners-Guide/html/
#!/bin/bash tells to the SO that this file is a script and that bash is the shell that must execute it. So you can found: #!/opt/bin/perl for perl scripts, #!/bin/csh for c-shell, #!/bin/zsh ...
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
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 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.