Strange Script behaviour with Grep


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Strange Script behaviour with Grep
# 8  
Old 05-04-2016
Quote:
Originally Posted by Don Cragun
Sorry. I just do not believe you.

If I run the following commands sequentially in an interactive shell that uses Bourne shell syntax:
Code:
$ 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:
Code:
XYZ=abc
echo "$XYZ"
echo '$XYZ'
echo "XYZ is set to '$XYZ'"

and execute it, I get the output:
Code:
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:
Code:
XYZ=abc

to:
Code:
set XYZ=abc

The only way that the command:
Code:
grep '$XYZ' file

and the command:
Code:
grep "$XYZ" file

produce the same, non-empty output is if the variable XYZ has been set with something like:
Code:
XYZ='$XYZ'

(assuming Bourne shell syntax) or:
Code:
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.
That helped ... The issue is resolved but i will dwell more into this in the future. Thanks Again.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Strange behaviour of grep in SunOS

Hi I ahve 2 files with below content: cat file1 FILE3 test1 test2 cat file2 file3 ghg test1 test2 i want to use file1 as pattern file and find out the missing strings in file2.(i.e ghg in this case regardless of c ase) I have tried: grep -i -v -f /path/file1 /path/file2 (6 Replies)
Discussion started by: pandeesh
6 Replies

2. Shell Programming and Scripting

strange behaviour script terminate before complete execution

I'm working on a script to make backup of various folder located on various host using different OS. I got a strange behaviour because the script donět process all lines of a configuration file, the script execute only one loop even the input file have 6 lines: This is the script: #!/bin/bash... (4 Replies)
Discussion started by: |UVI|
4 Replies

3. Red Hat

Crontab strange behaviour

Hi all, I'm having this scenario which for the moment I cannot resolve. :( I wrote a script to make a dump/export of the oracle database. and then put this entry on crontab to be executed daily for example. The script is like below: cat /home/oracle/scripts/db_backup.sh #!/bin/ksh ... (3 Replies)
Discussion started by: enux
3 Replies

4. Shell Programming and Scripting

Strange RegExp Behaviour

Hello, I was trying to identify lines who has a word of the following pattern "xyyx" (where x, and ys are different characters). I was trying the following grep - egrep '(\S)()\2\1' This pattern do catches the wanted pattern, but it also catches "GGGG" or "CCCC" patterns. I was trying to... (5 Replies)
Discussion started by: itskov
5 Replies

5. Shell Programming and Scripting

Strange behaviour with perl i/o?

Hi All, I got a strange problem here. I have a perl script which is fetching data from a database table and writing a file with that data. If i run that script from linux command line, the file it creates is a normal ascii text file without any binary character in it.But... (9 Replies)
Discussion started by: DILEEP410
9 Replies

6. Shell Programming and Scripting

Expect script strange behaviour

Hi people, I'm having some strange behaviour with an 'expect' script. spawn csession blah expect "Username: " send "userblah\r" expect "Password: " send "passwordblah\r" interact When I execute the script as root it runs perfectly. However, when executed as any other... (0 Replies)
Discussion started by: GarciasMuffin
0 Replies

7. UNIX for Dummies Questions & Answers

Strange Program behaviour

Had a strange thing going on with my code. It's ok I figured it out for myself.... (2 Replies)
Discussion started by: mrpugster
2 Replies

8. Shell Programming and Scripting

Strange behaviour from script in crontab

Apologies if this has been mentioned elsewhere, my search skills may be lacking somewhat today. I have a script that does the following (as a test): find . -name "*.txt" -exec file {} \; >>$sFullFilePath Now, the variable is set up up correctly in the script too. When I run the script... (1 Reply)
Discussion started by: PilotGoose
1 Replies

9. UNIX for Advanced & Expert Users

Strange sed behaviour

$ echo a.bc | sed -e "s/\|/\\|/g" |a|.|b|c| $ Is the behavior of the sed statement expected ? Or is this a bug in sed ? OS details Linux 2.6.9-55.0.0.0.2.ELsmp #1 SMP Wed May 2 14:59:56 PDT 2007 i686 i686 i386 GNU/Linux (8 Replies)
Discussion started by: vino
8 Replies

10. Shell Programming and Scripting

A Strange Behaviour!!!

Can some-one give me a view to this : I have a directory in an unix server, having permissions r-xr-xr-x .This directory is basically a source directory. Now there is another directory basically the destination directory which has all the permissions. Note:I log in as not the owner,but user... (5 Replies)
Discussion started by: navojit dutta
5 Replies
Login or Register to Ask a Question