Strange error.. help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Strange error.. help
# 1  
Old 05-12-2004
Strange error.. help

Hi,

When I give the following
$ ps -ef | grep `echo $var1` | grep -v "grep `echo $var1`" | awk '{print $3}' | grep -v `echo $var1

80892

But when I give the following (made as command substitution) , I get error
$var2=`ps -ef | grep `echo $var1` | grep -v "grep `echo $var1`" | awk '{print $3}' | grep -v `echo $var1``

ksh: 0403-057 Syntax error: `|' is not expected.

Similarly , when I give the following
$ps -ef | grep `echo $var2` | grep -v "echo $var1" | grep -e "-ksh" | wc -l

1

But when I give the following (made as command substitution) , I get error
echo `ps -ef | grep `echo $var2` | grep -v "echo $var1" | grep -e "-ksh" | wc -l`

Usage: grep [-E|-F] [-c|-l|-q] [-insvxbhwy] [-p[parasep]] -e pattern_list...
[-f pattern_file...] [file...]
Usage: grep [-E|-F] [-c|-l|-q] [-insvxbhwy] [-p[parasep]] [-e pattern_list...]
-f pattern_file... [file...]
Usage: grep [-E|-F] [-c|-l|-q] [-insvxbhwy] [-p[parasep]] pattern_list [file...]
ksh: 0403-057 Syntax error: `|' is not expected.

Where am i going wrong...
Pls help...
Thanks
# 2  
Old 05-12-2004
You know that you're trying to get the backticks to nest, but the shell doesn't. It sees the command as:
Code:
var2=`ps -ef | grep `echo $var1` | grep -v "grep `echo $var1`" | awk '{print $3}' | grep -v `echo $var1``
     |______________|          |_________________|          |_______________________________|          ||
          1                           2                                    3                            4

The korn shell introduced a new syntax to deal with this. Instead of
`echo $var`
do
$(echo $var)

But why do `echo $var` at all? In most cases, you can just use $var.
# 3  
Old 05-12-2004
And I just deleted your 2nd thread. Please don't do that...it's against the rules. We have a link to the rules at the bottom of every page.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Strange fork error while running script

more run.sh !/bin/bash input="data.txt" while IFS= read -r var do startdir="/web/logs" searchterm=$(echo $var | awk -F'=' '{print $1}') replaceterm=$(echo $var | awk -F'=' '{print $2}') find "$startdir" -type f -exec grep -l "$searchterm" {} + | while read file do if sed -e... (1 Reply)
Discussion started by: mohtashims
1 Replies

2. UNIX for Dummies Questions & Answers

Strange Error

I am receiving an error when i type the command dmesg sudo: sysmon : pam_authenticate: Conversation failure ; TTY=unknown ; PWD=/export/home/sysmon ; USER=root ; COMMAND=/opt/scripts/cronmgmt/synch_crontab.ksh Whats it about and how can I remove it ? (1 Reply)
Discussion started by: Junaid Subhani
1 Replies

3. Shell Programming and Scripting

Strange error in bash script

Howdy all, I have a scritp that does a sqldump. But for some goofy reason, a certain part of it behaves uber strange. It does a daily dump of my sql, according to parameters I enter in hardcode. The script is: #!/bin/bash APP_NAME="app_com_site" wikiname="wiki_com_site" ... (8 Replies)
Discussion started by: saariko
8 Replies

4. Shell Programming and Scripting

Strange error while splitting a file

Hi folks I am facing a strange error while splitting a '|' delimited file 'file1' based on column '3'. (File is 40 columns wide). I wish to create as many files 'file_n' from the file 'file1' as distinct values of the column '3'; in 'file1' eg: file1: qwe|qweqw|123|fg... (3 Replies)
Discussion started by: powerslave
3 Replies

5. Shell Programming and Scripting

Strange error on mpack from cronjob

I have a shell script which mails a file. It runs fine when executed at prompt, but from cronjob the following line gives an error: $ /opt/local/bin/mpack -s "TTW posts " $FILEPATH/ttw.html myemail@gmail.com Error is : (some junk chars) followed by No such file or directory. Before this... (5 Replies)
Discussion started by: sentinel
5 Replies

6. AIX

Strange error with file access permissions

All, I am trying to copy some data from /admin/reports/Sept/ccn/c_ivsstr01 to /home/users/myhomedir and I am getting an error I have never seen before: The file access permissions do not allow the specified action. The permissions on the file are -rw-r--r-- and I am the owner of the file... (3 Replies)
Discussion started by: kjbaumann
3 Replies

7. UNIX for Dummies Questions & Answers

Strange error

Hi all, i executed a script. cat <filename> | grep <pattern> | awk '{print $1}' | read a i get the answer when i execute it in the shell env (no problem with that) as ./<name>.ksh when i tried the same in cron (as an entry in cron) value is not being read in the variable a through... (1 Reply)
Discussion started by: matrixmadhan
1 Replies

8. Shell Programming and Scripting

ed strange error message

When I start ed as regular user, following message is displayed: $ed ERROR: tempnam failed: Permission denied $ I think, following error produced in vi when search results from previous error: No previous regular expression Setting TMPDIR variable cause no effect. As root all works... (6 Replies)
Discussion started by: frenki
6 Replies

9. Programming

strange error

hi, when i try to compile, i got the following error message, what does it mean? $gcc auto.cpp /usr/tmp/ccmuE12B.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0' collect2: ld returned 1 exit status thanks (1 Reply)
Discussion started by: laila63
1 Replies
Login or Register to Ask a Question