Visit Our UNIX and Linux User Community


command substitution problems with csh using grep


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting command substitution problems with csh using grep
# 1  
Old 01-03-2006
command substitution problems with csh using grep

I am trying to set a command into a variable in a csh script using command substituion with ``. I am having a problem with ps command combined with grep. The command is as follows (shows processes running with the word gpts in them).

/usr/ucb/ps axwww | grep gpts

this works fine at the command prompt but I get an error "set: No match" when trying to use it in a csh script as follows

set PS1=`/usr/ucb/ps axwww | grep gpts`
echo $PS1

It works fine for other commands such as ls -la | wc, entered as follows

set LIS=`ls -la | wc`
echo $LIS

Anyone with any ideas with what's wrong with the first command? I have tried substituting a variable for gpts but that didn't work either
# 2  
Old 01-14-2006
$PS1 is defined as the primary prompt for most shells I know of --- change your variable name and check again
# 3  
Old 01-14-2006
The prompt variable is csh's equivalent of PS1.

PS1 is the primary prompt for Bourne-based shells.

When you run your ps command at the command line, you'll see that there is a "?" somewhere in the output. This is confusing csh.

Before you call the ps command in your script, include the line:

set nonomatch

Then it should work. Personally, I'd say ditch csh and use a Bourne-based shell for scripting.

Cheers
ZB

Previous Thread | Next Thread
Test Your Knowledge in Computers #270
Difficulty: Easy
Steve Jobs died of respiratory arrest related to a car accident at age 56 on October 5, 2011.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script having variable substitution problems

Hi I am setting the variables like this : setenv MODULE1 modem5__3 setenv MODULE2 modem5__2 setenv MODULE3 modem_ctrl_1_1 setenv MODULE4 modem_1_0 setenv COUNT 10 I am having a bash script as shown below ################################################ #!/bin/bash for ((... (5 Replies)
Discussion started by: kshitij
5 Replies

2. Shell Programming and Scripting

Substitution after using grep

Hallo Team, I would like to edit my output(files) after using grep manipulation. this is how my code looks like: grep Originating *2013*|grep -v "ACCOUNT IN RECALC"|grep -v MOBIFIN-TRANSIT|grep -v ",Call Forward Not Reachable"|grep "Unclear scenario:On-net to Off-net PGW, On-net to Off-net... (8 Replies)
Discussion started by: kekanap
8 Replies

3. Shell Programming and Scripting

csh grep analog

Hi everyone, I'm trying to make a csh script analog for grep. I need to run through the directory which is arg, find a word (arg) in the files, and echo their names. Here's what I got if ($#argv != 2) then echo "Usage: $0 directory word" echo "Shows files which contains words" exit... (3 Replies)
Discussion started by: vanguardua
3 Replies

4. Shell Programming and Scripting

Problems with substitution between two variables

To all geeks, What I want to achieve: 1. Accept two filenames from user and store the filenames in two variables (FILE1 and FILE2) 2. Check if files exisits. If doesn't, then exit 3. If files exist, look for a particular string in both files 4. If the string exists, then change the... (8 Replies)
Discussion started by: Deepak Tulsani
8 Replies

5. Shell Programming and Scripting

Execution problems with grep command in scripting

Hi All, I was looking for grep command option which can exactly matches the word in a file, for examples you may be seeing one word that is also in another word, there might be lkk0lv23 and a lkk0lv234 in which case lkk0lv23 will put BOTH hosts from the grep in. I was using this in a bash... (2 Replies)
Discussion started by: bobby320
2 Replies

6. Shell Programming and Scripting

Cannot compare argument in if statement in csh/grep command if argument starts with -

If ($argv == “-debug”) then Echo “in loop” Endif But this is not working. If I modify this code and remove “-“, then it works. Similarly I am getting problem using grep command also Grep “-debug” Filename Can someone please help me on how to resolve these... (1 Reply)
Discussion started by: sarbjit
1 Replies

7. Shell Programming and Scripting

Array problems in CSH

Hi all, I want to use some commands and I wrap them into an array, like follows: set ALIAS_AR = ( "ls -ltr|wc -l" \ "ps -ef|grep -v grep |grep tty|wc -l" \ "who|wc -l" ) Then I use a while loop to call every step: set no = 1... (3 Replies)
Discussion started by: tpltp
3 Replies

8. Shell Programming and Scripting

AWK in CSH script problems

Hello Guys, I was trying to obtain the information from the /etc/passwd file, here was my script: 38 echo -n "What's your login name? " 39 set logname=$< 40 echo "Your login name is $logname, your user's ID is `grep $logname /etc/passwd|awk -F: '{print $3}'`" 41 echo " Your home dir is... (1 Reply)
Discussion started by: tpltp
1 Replies

9. Shell Programming and Scripting

word substitution in csh

I have data that looks something like this: term1/term2/2005-12-01 13:20:30/term4 I need to make it look like this: term1/term2/20051201132030/term4 I am using a csh script. I have tried to do it by first converting the date/time to the format in which I want it, and then replacing it... (1 Reply)
Discussion started by: oprestol
1 Replies

10. Shell Programming and Scripting

sed substitution problems

Hi falks, I need to substitute in my ksh program, parameter (full path of directory) ,which is sent from outside program, with another parameter (another full path of directory) ,which is known and validated inside my program. I tried to use "sed" ,but i failed. For example: ... (2 Replies)
Discussion started by: nir_s
2 Replies

Featured Tech Videos