NEWS: Total Picture Views: 155282 | Total Article Views: 165599 | Top 5 Most Popular Article: 1. Am I Stuck Algorithm with Becker Robot | 2. PickUpThings with Becker Robot | 3. How to read a JSON and work with it | 4. Encrypted Data GUI (Download .Zip) | 5. Create Wall and Things with Becker

Get Number Of Argument And Loop The Value With A Counter Bash

Description:

In this example I will be showing how to read the argument of a command and loop it with a counter.

(example = filename)
Example: bash example Hi Hello Welcome
Will return:
1 : Hi
2 : Hello
3: Welcome

Code:

#!/bin/bash

echo "$0"
typeset -i counter=1
for arg in $*
do
        echo "$counter :  $arg"
        counter=counter+1
done
exit 0
Attachments: None

Tags: For Loop echo increment counter

Total Views: 810

My name is Jean-Mathieu

I created this website so other people could enjoy finding useful stuff easier. If you have any question do not hesitate to contact me.

jean8mathieuCreated on 02/03/15


affiliate_link

Disclosure: We are a website that needs compensation to operate like any other website on the internet.
We may receive consideration for our reviews but we are totally unbiased and do not accept paid reviews or fake reviews claiming to be something they are not.