Echo and grep issues

 
Thread Tools Search this Thread
Operating Systems Linux Red Hat Echo and grep issues
# 1  
Old 04-29-2015
Echo and grep issues

Is there an environment issue that would not allow the following not store and pass the value into this field:
Code:
underScorePresent=`echo $USER | grep "_" | wc -l`

It is running on a new redhat 6.5 OS. The value $USER is set to cpac. It is a vendor code and they are saying it is environment issue and not a code/script issue. Any thougths?

Last edited by Franklin52; 04-30-2015 at 10:30 AM.. Reason: Please use code tags
# 2  
Old 04-29-2015
They mean that $USER is set by some shells only.
I have always used "${USER:-$LOGNAME}" therefore - display LOGNAME if USER is not set.
BTW you can simplify the shell code to
Code:
underScorePresent=`echo "${USER:-$LOGNAME}" | grep -c "_"`

(as well returns 0 or 1).
Or to this one
Code:
[[ "${USER:-$LOGNAME}" != *_* ]]; underScorePresent=$?

Or even to this one (returns 0 or a positive number)
Code:
underScorePresent=`expr x"${USER:-$LOGNAME}" : x".*_"`


Last edited by MadeInGermany; 04-29-2015 at 12:37 PM..
This User Gave Thanks to MadeInGermany For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep echo awk print all output on one line

Hello, I've been trying to find the answer to this with Google and trying to browse the forums, but I haven't been able to come up with anything. If this has already been answered, please link me to the thread as I can't find it. I've been asked to write a script that pulls a list of our CPE... (51 Replies)
Discussion started by: rwalker
51 Replies

2. Shell Programming and Scripting

Using echo, grep and wc and outputing to text file

My current line command is as follows: echo -n "text: " ; grep "blah text" ../dir1/filename | wc -l The output to the screen is as needed, but how do I print to a text file? (9 Replies)
Discussion started by: ncwxpanther
9 Replies

3. UNIX for Dummies Questions & Answers

Issues while pattern matching using grep

Hi, I have a file f1 wi the following data f1.txt ======== Report ID Report Name ----------------------------------------------------------------- Post Requests : 2 Post successes : 2 ============================================= I need to search for the... (2 Replies)
Discussion started by: RP09
2 Replies

4. Shell Programming and Scripting

echo and grep commands

Hey im new in this...anything will be helpful... The user will input the word or phrase .... I want to search the user input in file (by lines) but not all then with this line search on another file ( with the specific line) and show to the user. Example: file1.txt ======= a aa aaa... (2 Replies)
Discussion started by: Sundown
2 Replies

5. Shell Programming and Scripting

Issues in grep command in Linux

Hi All I have a file containing following records: $HEW_TGT_DB2_USER=hbme_bi2 $prmAttunityUser=ais $DS_USER=hbme_bi2 $prmStgUser=hbme_bi2 $prmuser=hbme_bi2 $prmStgPass=hbme_bi2 $prmpwd=hbme_bi2 $prmAttunityUser=ais Say suppose the name of the file is test4.txt When i fire this... (5 Replies)
Discussion started by: vee_789
5 Replies

6. Shell Programming and Scripting

Issues with grep -w

I am trying to use grep -w something as shown below. grep -w "$a" $LOG1 It is not giving me neither any error nor any data. I am facing the issue while i run this command inside a script. But i am getting the data if i run the above command outiside the script. here $a=08/11/2009 21 i... (13 Replies)
Discussion started by: rdhanek
13 Replies

7. Shell Programming and Scripting

help with grep and echo

Can't get this to work. Something is wrong with the systax maybe. :o if ] && ] ; then: Thanks (2 Replies)
Discussion started by: rstone
2 Replies

8. UNIX for Dummies Questions & Answers

How do I output or echo NONE if grep does not find anything?

I am performing a grep command and I need to know how to echo "NONE" or "0" to my file if grep does not find what i am looking for. echo What i found >> My_File grep "SOMETHING" >> My_File I am sure this is easy, I am sort of new at this! Thanks (2 Replies)
Discussion started by: jojojmac5
2 Replies

9. UNIX for Dummies Questions & Answers

GREP issues

Hi all, I am trying to perform a simple task with grep, this is what I execute: grep -i -n 'error|fail|warning' cl_less.out when I execute it it does not give any errors, as in the command worked and back to the command prompt, but if I run each grep independently the I do get a real fail: ... (8 Replies)
Discussion started by: sqloyd
8 Replies

10. Shell Programming and Scripting

small question of echo | grep command

Hi, i've got the following: a=`echo $b | grep '^.*/'` i'm storing in the variable the value of the variable b only if it has a / somewhere. It works, but i don't want to print the value. How do i give the value of b to the grep command without the echo? thanks! (5 Replies)
Discussion started by: kfad
5 Replies
Login or Register to Ask a Question