The Cookie Machine - Click here to drag window

DUMMY TEXT - Real text set in assets/js/theCookieMachine.js

Views: 158β€…    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: November 24, 2022    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.

⇧ How to diagnose Software Updater issue? It just pops up a window with no content How to remotely use a computer from another computer over the local network?  β‡©