Capturing a non-result of a command


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Capturing a non-result of a command
# 1  
Old 05-26-2009
Capturing a non-result of a command

The following pseudo-code should be clear to what I am trying to achieve:
Code:
if [ {nothing is returned from kldstat | grep linux} ]; then
	kldload linux
	echo 'linux_enable="YES"' >> /etc/rc.conf
fi

What is the proper syntax or operator for the test?
Thanks in advance
# 2  
Old 05-26-2009
Do you mean the result of the [ command kldstat|grep linux ] returns nothing?
(sorry no linux around...) why not put the result in a variable then test the variable?
# 3  
Old 05-26-2009
Thank you for your response. Yes, in some cases the following occurs:
Code:
# kldstat | grep linux
#

This is FreeBSD 7.1 by the way, whereby Linux emulation needs to be enabled. So your suggestion means I need to evaluate $? or use trap somehow? Please advise.
# 4  
Old 05-26-2009
Quote:
Originally Posted by figaro
Thank you for your response. Yes, in some cases the following occurs:
Code:
# kldstat | grep linux
#

This is FreeBSD 7.1 by the way, whereby Linux emulation needs to be enabled. So your suggestion means I need to evaluate $? or use trap somehow? Please advise.
Something like this?

Code:
kldstat | grep linux > /dev/null 2>&1
if [ $? == 0 ]; then
  # linux found
fi

Regards
# 5  
Old 05-26-2009
Or ...

Code:
if ! kldstat | grep linux; then
   # do something
fi

Or ...

Code:
if [ $(kldstat | grep -c linux) -eq 0 ]; then
    # do something
fi

# 6  
Old 05-26-2009
Thanks, your suggestions worked.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Linux find command seems to not transmit all the result to the '-exec command'

Hello. From a script, a command for a test is use : find /home/user_install -maxdepth 1 -type f -newer /tmp/000_skel_file_deb ! -newer /tmp/000_skel_file_end -name '.bashrc' -o -name '.profile' -o -name '.gtkrc-2.0' -o -name '.i18n' -o -name '.inputrc' Tha command... (3 Replies)
Discussion started by: jcdole
3 Replies

2. Shell Programming and Scripting

Grep command giving different result for different users for same command

Hello, I am running below command as root user #nodetool cfstats tests | grep "Memtable switch count" Memtable switch count: 12 Where as when I try to run same command as another user it gives different result. #su -l zabbix -s /bin/bash -c "nodetool cfstats tests | grep "Memtable switch... (10 Replies)
Discussion started by: Pushpraj
10 Replies

3. Shell Programming and Scripting

Capturing first output from 'top'-likes command

Is this a stupid code?? top > top.out & sleep 2 kill %1 cat top.out Thanks, (6 Replies)
Discussion started by: Shawn, Lee
6 Replies

4. Shell Programming and Scripting

Capturing the output from an exec command

Hi, I'm new to ksh - unix platform. I'm writing a small script which will search my current directory and will search for file names which it takes input from the users. Here is the code I'm having. 1 #!/bin/ksh 2 echo "enter a file name to be searched in the current dir : " 3 read... (1 Reply)
Discussion started by: avik
1 Replies

5. UNIX for Dummies Questions & Answers

Capturing output from grpck command on AIX

I'm having trouble capturing output from the following command on AIX: grpck -n ALL > error.out It gives me the results on the screen but my file is blank. I have no trouble capturing output from "ls > ls.out", but doesn't seem to work with the grpck command. Any ideas? Thanks. (2 Replies)
Discussion started by: pdtak
2 Replies

6. UNIX for Advanced & Expert Users

Capturing command prompt from a C/C++ program

Hello, I would like to capture the password request of a process (like passwd or smbpasswd, ...) from a C/c++ program. My idea was to use pipes, but they capture only the stdout/stdin, not the request itself (e.g. "Enter password for user tom:" is not captured by pipes). In other words, my... (1 Reply)
Discussion started by: mousec
1 Replies

7. Shell Programming and Scripting

Capturing last command execution status in a script.

How to capture output or numeric part given by $? command into the variable? If I go for var=`$?` then $var is found empty. (2 Replies)
Discussion started by: videsh77
2 Replies

8. Shell Programming and Scripting

Capturing shell script command output

I am trying to check to see if a file exists on a ftp server, well, I know that cant be done, atleast directly, So I came up with this small script ftp -n $HOST <<END_SCRIPT quote USER $USER quote PASS $PASSWD cd public_html/crap dir $FILE quit END_SCRIPT Where the $ variable... (2 Replies)
Discussion started by: designflaw
2 Replies

9. UNIX for Dummies Questions & Answers

echo command result

hello how can i print to screen the result of this command ? echo "pwd | sed 's/.*foo//'" when i type it im geting it printed as string "pwd | sed 's/.*DevEnv//'" and not the result of the operetion. tnx (2 Replies)
Discussion started by: umen
2 Replies

10. IP Networking

FTP command result

Hi there! I've used the ftp command to transfert datas between two linux box. The answer of this command, was: It strange because the transfert was complete and it brings two messages, the first is successful from PORT command and the second is an error from EPRT command! So, It seems that... (1 Reply)
Discussion started by: nymus7
1 Replies
Login or Register to Ask a Question