I have this string:
address 0 address-set hostname-of-a-host
and this grep command:
file=`/bin/grep -ilr ".*$host_name.*" /path/to/some/files/*
Where:
host_name=`echo $line | cut -d ' ' -f 4-`
I want to get the host_name and if in a path files that contains it.
So, this is the code:
line="address 0 address-set hostname-of-a-host"
host_name=`echo $line | cut -d ' ' -f 4-`
file=`/bin/grep -ilr ".*$host_name.*" /path/to/some/files/*
These commands works in a shell without issues. However, the script returns an empty "file" variable. I don't know why they don't work in script but works in shell.
This is the output on a bash execution (i' m sorry but i have to modify :
root@cpm:/path/# line="address 0 address-set hostname"
root@cpm:/path/# host_name=`echo $line | cut -d ' ' -f 4-`
root@cpm:/path/# file=`/bin/grep -ilr ".*$host_name.*" /path/to/some/files/*
root@cpm:/path/# echo $file
/path/to/some/files/file1