In this post, lets look at solving a recurring task of having to launch bash scripts with custom parameters.

I'll demonstrate this with a sample problem of Getting the IP address of any domain

There are various ways of solving this problem, but my persistent preference is to use the all powerful terminal and keep things simple and minimalistic.

Parameters to a script can be simple passed like below:

bash './shell/'

The script for ./shell/ is as follows:


echo "URL is: $URL"

IP=$(dig +short $URL | head -1)
echo "IP of $URL is: $IP"


Get IPs of multiple domains

Getting the IP of domains is pretty simple too!

The script that loops through the domains called is as follows:


# execute using:
# bash './shell/' '' '' '' ''

for domain in "$@"
  echo "URL is: $URL"

  IP=$(dig +short $URL | head -1)
  echo "IP of $URL is: $IP"

Execution is pretty simple again!

bash './shell/' '' '' '' ''