giving input from console

echo " hi "
hostname=$0
username=$1



how to pass values to $0 and $1

main.sh andrew teja


is it correct
$0 is the name of the program itself, so any parameters can be transferred beginning with $1, $2 and so on.
e.g: command sh qwerty alpha, bravo will give:
qwerty -> $0
alpha - > $1
bravo -> $2
Here's the program named main.sh:
1
2
3
4
5
6
7
8
9
10
#!/bin/bash

hostname=$1
username=$2

echo "hi!"
echo $hostname
echo $username

exit 0

And the output:
1
2
3
4
sh main.sh andrew teja
hi!
andrew
teja


Happy...BASHing!
Last edited on
Topic archived. No new replies allowed.