Below is my code to which i'm trying to pass a 3 argument like "client name with datacenter" hostname ip
so, "client name with Datacenter" is the 1st argument likewise hostname and ip is 2nd and 3rd argument.
is there any way i could pass the first argument as it is with spaces, as of now it's now not working as expected, because after space every word it's taking as different argument.
Actual issue is i want to pass this whole sentence as argument. "Actual Servers to be added". Is there any way i could do this? So this argument will be further used to look into a text file and search the string where the additional arguments $2 and $3 will get add.
#! /bin/bash
user=whoami
#file1=/home/xymon/server/bin/ghostlist.cgi
logfile=logfile1 ###Local Log file######
client="$@"
hostname=$2
ip=$3
####taking backup while editing hosts file everytime#####
#cp -pr /home/xymon/server/etc/hosts.cfg "/home/xymon/server/etc/hosts.$(date +"%Y%m%d")"
echo $ip
echo $hostname
echo "hostfile is modified @ date
" >>$logfile
printf '%s\n' 'g/"'$client'"/+2i' ''$ip' '$hostname' # testip "TRENDS:*,netstat:netstat|netstat1|netstat2|netstat3"' 'wq' | ed -s hosts
"$1"
in your script. Could you clarify your issue? – Kusalananda Dec 17 '20 at 20:42./script
. See also my first comment again. – Kusalananda Dec 21 '20 at 07:51"$1"
in your code. You use"$@"
which is all arguments. – Kusalananda Dec 21 '20 at 12:14