#!/bin/bash
hostname=$1; shift
for hostname in $1
do
ping $hostname
done
I want to run the above script as hostname.sh yahoo.comgoogle.comcnn.com. I want to shift each hostname to $1. How can do that with above code as currently it's not shifting.
You know that $# tells you how many positional parameters are present. Executing shift will decrement the value of $# as a side effect.
Can you come up with a while loop conditioned on the value of $# with the code in the loop using "$1" and the last command in your loop being a shift ?