Views:
233β
Votes: 1β
β
Solution
Tags:
bash
scripts
Link:
π See Original Answer on Ask Ubuntu β§ π
URL:
https://askubuntu.com/q/1192784
Title:
How do I make a shell program run with the script name? and script help
ID:
/2019/11/30/How-do-I-make-a-shell-program-run-with-the-script-name_-and-script-help
Created:
November 30, 2019
Edited: November 30, 2019
Upload:
September 15, 2024
Layout: post
TOC:
false
Navigation: false
Copy to clipboard: false
The main problem is the script has the wrong name of prargs.sh
when the filename should be prargs
. The second problem is there should be a βshebangβ at the top telling the system it is a bash script:
#!/bin/bash
while [ "$#" -ne 0 ]
do
((Count++))
echo "$Count: $1"
shift
done
Note: Your script was missing the 1:
, 2:
, etc. parameter count. Iβve added that missing pieces with:
((Count++))
echo "$Count: $1"
So when you run the script you now see:
$ prargs a 'b c' d
1: a
2: b c
3: d
The next problem is calling the prargs
without specifying a location in front. If you place your script in one of your paths it will be found without specifying a directory. To see your current paths use: echo $PATH
. Many people will create a path in their home directory for personal scripts:
mkdir -p $HOME/bin
After this reopen the terminal to have it in your path. So create your script as $HOME/bin/prargs
and then mark it executable:
chmod a+x $HOME/bin/prargs
After this no matter what your current directory is you can type prargs a 'b c' d
.