Add a “shebang” at the top of your file:
#!/bin/bash
And make your file executable (chmod +x script.sh
).
Finally, modify your path to add the directory where your script is located:
export PATH=$PATH:/appropriate/directory
(typically, you want $HOME/bin
for storing your own scripts)
More Related Contents:
- Why would I create an alias which creates a function?
- Are shell scripts sensitive to encoding and line endings?
- Difference between sh and Bash
- Command not found error in Bash variable assignment
- Pass commands as input to another command (su, ssh, sh, etc)
- Why would a correct shell script give a wrapped/truncated/corrupted error message? [duplicate]
- Why is testing “$?” to see if a command succeeded or not, an anti-pattern?
- What is the difference between $(command) and `command` in shell programming?
- Reading quoted/escaped arguments correctly from a string
- How can I remove the extension of a filename in a shell script?
- I just assigned a variable, but echo $variable shows something else
- How can I declare and use Boolean variables in a shell script?
- Ubuntu says “bash: ./program Permission denied” [closed]
- Assignment of variables with space after the (=) sign?
- How to echo shell commands as they are executed
- How to get a password from a shell script without echoing
- Count occurrences of a char in a string using Bash
- How to redirect output of an entire shell script within the script itself?
- How does Ctrl-C terminate a child process?
- source command not found in sh shell
- What does it mean in shell when we put a command inside dollar sign and parentheses: $(command)
- Should I use a Shebang with Bash scripts?
- Is there an elegant way to store and evaluate return values in bash scripts?
- ^word^replacement^ on all matches in Bash?
- Can I export a variable to the environment from a Bash script without sourcing it?
- How to urlencode data for curl command?
- Assigning default values to shell variables with a single command in bash
- Calling shell functions with xargs
- How to write a bash script to set global environment variable?
- Escaping forward slashes in sed command [duplicate]