0

i am trying to capture the return value of simple command:

i.e:

pwd

where can i find the relevant return value without stdout it to file?

Thanks koby

3
  • You need to specify the shell used. Commented Nov 4, 2010 at 13:02
  • i.e : awk 'NR==7' Single.log will return line 7 in Single.log Commented Nov 4, 2010 at 13:20
  • That's very nice, and what does echo $SHELL says ? Commented Nov 4, 2010 at 13:23

5 Answers 5

2

you can use `pwd`

for example:

$ setenv MY_PWD `pwd`
$ echo $MY_PWD
/my/current/path
Sign up to request clarification or add additional context in comments.

6 Comments

When typing line : MY_PWD=$(pwd) it says "MY_PWD=: Command not found."
you have to make sure you have no spaces before the = sign: MY_PWD=$(pwd)
@user497159 what shell are you using? In csh for example you should use setenv to create an enviroment variable.
can you please tell me if the new command (i.e. setenv MY_PWD `pwd`) works ?
I'm glad it finally works ! Can you please validate my answer then ? ;)
|
1

You can try `pwd`

ole@...:~$ echo `pwd`
/home/ole
ole@...:~$

3 Comments

how do you print those ... backtick ? :)
Do you mean how I got Stack-O to print them without converting them to "codeblock"? Escaped it with a backslash :-)
$ (and everything before it) is the shell prompt. Ole means you should type echo `pwd`.
1

The first question people should be asking is... what shell are you running this in?

$ MY_PWD=$(pwd) will work in sh-like.

I think the `pwd` will call a subshell, but again, depending on the shell, the syntax to set the output value to a variable will depend on your shell.

1 Comment

Then you should be able to write "set variablename = `pwd`; echo $variablename"
0
echo $?

Is that what you are looking for?

Comments

0

http://tldp.org/LDP/abs/html/exit-status.html

use $?

1 Comment

This is specifically what he doesn't want

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.