-rw-r--r-- 1 wluser wluser 0 May 3 17:35 10min_log
You see 0 bytes.
But when i type this manually grep '2016-05-03 17:3' /tmp/logs/vel.log i see 1000s of lines like below.
Like you can see when i manually type the grep command i see 1000s of line but when the same command goes in the script the redirected output to 10min_log shows 0 bytes and no data.
Why ?
Note: when i change grep '$LOGDATE' /tmp/logs/vel.log>10min_log to grep $LOGDATE /tmp/logs/vel.log>10min_log i.e remove the single quotes'' then it works. But i want to grep 2016-05-03 17:3 as one text hence i need the single quotes or if there is another solution ??
Note: I was able to overcome the issue by using double quotes ""
Note: i m with the same user and grp as the directory i.e there is no permission issues.
single-quote characters are not special inside a double-quoted string; so in that case $LOGDATE is expanded because it is in a double-quoted string; not inside a single-quoted string.)
If I run the following commands sequentially in an interactive shell that uses Bourne shell syntax:
$ XYZ=abc
$ echo "$XYZ"
abc
$ echo '$XYZ'
$XYZ
$ echo "XYZ is set to '$XYZ'"
XYZ is set to 'abc'
$
I get the output shown in bold text from those commands. And, if I put the commands in a script:
XYZ=abc
echo "$XYZ"
echo '$XYZ'
echo "XYZ is set to '$XYZ'"
and execute it, I get the output:
abc
$XYZ
XYZ is set to 'abc'
If you use a shell that uses csh syntax instead of Bourne shell syntax, you still get the same results if you change the 1st command from:
XYZ=abc
to:
set XYZ=abc
The only way that the command:
grep '$XYZ' file
and the command:
grep "$XYZ" file
produce the same, non-empty output is if the variable XYZ has been set with something like:
XYZ='$XYZ'
(assuming Bourne shell syntax) or:
set XYZ='$XYZ'
(assuming csh shell syntax) and the file named file contains the literal string $XYZ unless you have a function named grep , an alias for grep , or a non-standard version of the grep utility that is found in your PATH environment variable before the standard version of the grep utility.