not found message


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting not found message
# 8  
Old 02-21-2012
Quote:
Originally Posted by goddevil
I have changed my shebang to #!/usr/bin/bash and this only increases the errors that i get. I still get the output that i require though



I am trying to see if VAR1 consists of the string 63u and if it does, then execute the statements under if
2 things are wrong -
1. You are missing a double quote in your expression (echo $VAR1")
2. Your test expression can't just be the output of the grep command - you need to perform some kind of test operation on it.

Try the following (using $() syntax instead of the deprecated backticks):

Code:
if [[ -n "$(echo "$VAR1" | grep 63u)" ]]

This User Gave Thanks to mobitron For This Post:
# 9  
Old 02-21-2012
Code:
VAR1="hostname63uf.group"
if [[ "$var1" =~ /63u/ ]]
then
        SUB1="yes"
        SUB2="23421"
else
        SUB1="no"          
fi

if [ "$SUB1" == "no" ]
then
        SUB2="48421"
else
        SUB2="47615"
fi
echo $SUB1 $SUB2

This User Gave Thanks to balajesuri For This Post:
# 10  
Old 02-21-2012
Thanks a mil for the replies everyone. I modified my code and the below code works as expected

Code:
VAR1="hostname63uf.group"
if [[ `echo "$VAR1" |grep 63u` ]]
then
        SUB1="yes"
        SUB2="23421"
else
        SUB1="no"          
fi
if [ "$SUB1" == "no" ]
then
        SUB2="48421"
else
        SUB2="47615"
fi
echo $SUB1 $SUB2

# 11  
Old 02-21-2012
Quote:
Originally Posted by mobitron
Your test expression can't just be the output of the grep command - you need to perform some kind of test operation on it.

Try the following (using $() syntax instead of the deprecated backticks):

Code:
if [[ -n "$(echo "$VAR1" | grep 63u)" ]]

You're mistaken. You can indeed just test the result of a command subsitution or any shell expansion by itself. [[ -n "..." ]] and [[ "..." ]] are synonymous.

Regards,
Alister
These 2 Users Gave Thanks to alister For This Post:
# 12  
Old 02-21-2012
Quote:
Originally Posted by alister
You're mistaken. You can indeed just test the result of a command subsitution or any shell expansion by itself. [[ -n "..." ]] and [[ "..." ]] are synonymous.

Regards,
Alister
I was indeed mistaken. Thanks for putting me straight!
# 13  
Old 02-21-2012
Quote:
Originally Posted by goddevil
Thanks a mil for the replies everyone. I modified my code and the below code works as expected

Code:
if [[ `echo "$VAR1" |grep 63u` ]]
then

Congratulations on getting it working. In case you're interested, here's a more direct way of accomplishing that task:
Code:
if echo "$VAR1" | grep -q 63u
then

If for some reason your grep does not support -q:
Code:
if echo "$VAR1" | grep 63u >/dev/null
then

Regards,
Alister
# 14  
Old 02-21-2012
Quote:
Originally Posted by alister
Congratulations on getting it working. In case you're interested, here's a more direct way of accomplishing that task:
Code:
if echo "$VAR1" | grep -q 63u
then

If for some reason your grep does not support -q:
Code:
if echo "$VAR1" | grep 63u >/dev/null
then

Regards,
Alister
Thanks Alister. I did not know that you could do away with the [] braces. So in effect what i've been doing is tantamount to using a double negative speech.

Code:
if echo "$VAR1" | grep 63u >/dev/null

worked a charm

The grep does not support -q and i get the following :
Quote:
grep: illegal option -- q
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Ssh from a ksh returning not found message

Script name is test.ksh I know that that the ssh command is working properly, this can be verified by the value returned in respond variable. It is unique to the remote server _____________________________________________________ respond=$(ssh $remoteHost find... (3 Replies)
Discussion started by: Adagio
3 Replies

2. Shell Programming and Scripting

Search for a tag and display a message if not found.

Hi All, I am working with a XML file. Below is part for the file. <Emp:Profile> <Emp:Description>Admin</Emp:Description> <Emp:Id>12347</Emp:Id> </Emp:Profile> <Emp:Profile> ... (7 Replies)
Discussion started by: Girish19
7 Replies

3. Shell Programming and Scripting

not found message

I am executing the following script in a bash shell in solaris and it throws up the following message : But i get the output that i require nevertheless. Can anyone please spot what is causing the warning and how do i get it go away? VAR1="e6842w2334f76figtl5.systems.grp" if 76fig`... (2 Replies)
Discussion started by: goddevil
2 Replies

4. Shell Programming and Scripting

How to grep for message and if found display filename?

Hi i'm new to the forum and was hoping someone could help me with the following query. I do alot of testing and have hundreds of log files output. I have a script (someone else wrote) which finds all the passed and failed logs and puts a number in a column onto a webpage: e.g: Pass ... (4 Replies)
Discussion started by: defamer
4 Replies

5. UNIX for Dummies Questions & Answers

Not Found message in script execution

Hi gurus, I'm having a strange problem and I hope you can help me solving it. I'm working in Unix Solaris, version 5.10, ksh. I have a script with environment variables which I have to execute prior to other scripts. The script belongs to userA and when I log in, and cd to its directory. It... (4 Replies)
Discussion started by: ermur
4 Replies

6. Shell Programming and Scripting

why the message not found in the file

Hi, I am a newbie for shell programming and met some question about redirect output to a file. See the details. #!/usr/bin/sh ... ./doSomething.pl >> RAW_DATA echo "testing is done !" >> RAW_DATA Descirption: doSomething.pl do a bit complex things and output some message. I append... (3 Replies)
Discussion started by: programmerBegin
3 Replies

7. Shell Programming and Scripting

Function not found message

I have shell script as below: #!/bin/ksh #set -xv function set_variable { VARIABLE_NAME=$1 CURRENT_PATH=`pwd` if ; then echo "\nconfiguration_file.lst file not found in $CURRENT_PATH/common/common_scripts" exit 1; fi VARIABLE_COUNT=`cat... (2 Replies)
Discussion started by: findprakash
2 Replies

8. Programming

How to limit max no of message in a posix message queue

Hii can anyone pls tell how to limit the max no of message in a posix message queue. I have made changes in proc/sys/fs/mqueue/msg_max But still whenever i try to read the value of max. message in the queue using attr.mq_curmsgs (where struct mq_attr attr) its giving the default value as 10.... (0 Replies)
Discussion started by: mohit3884
0 Replies

9. Shell Programming and Scripting

Return a message when a file is not found

Hi there, I am writing a script to look for tmp log files that have not been access within the last 10 days. I am using the follwing command within the script: find /var/tmp -name *log -atime -9 ¦xargs What I would like to be able to do would be to display a message if there is no... (3 Replies)
Discussion started by: lodey
3 Replies

10. UNIX for Advanced & Expert Users

unknown error message "sh: No: not found"

I am getting this error message (sh: No: not found) and I have no idea what line in my unix script its coming from or what it means. Can anyone help? thanks, Cindy (2 Replies)
Discussion started by: cindytucci
2 Replies
Login or Register to Ask a Question