2

I have a script called a.sh, contents of which are:

//a.sh:

#!/bin/bash
temp=0
while [ "$temp" -ne 500 ]
do
    echo `date`
    temp=`echo "$temp+1" | bc`
    sleep 1
done
----------------------------------

Another script namedb.sh, contents of which are:

// b.sh:

#!/bin/bash

`a.sh`

exit
----------------------------------

When i execute a.sh separately, i'm able to see the output.. but, when i execute b.sh, i'm not able to see the output on the console.. (i tried a few times - to redirect the output of a.sh - but not being successful).

So, what i need is the redirection, which will enable me to see the output of a.sh's contents when i execute b.sh - on the console.

Thanks, Ravi.

1
  • Someone reformat, please, this is unreadable. Commented Jul 6, 2011 at 6:43

4 Answers 4

5
`a.sh`

in your b.sh means take the output of a.sh and use it as a command with arguments. you just have to execute a.sh in b.sh

$A_SH_PATH/a.sh instead of

`a.sh`
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot for the clarification.. this simply means, my understanding of backticks was wrong.. Thanks for enlightening
Thanks a lot for the clarification.. so, this implies my understanding of backticks was not correct. Thanks for the help.
0

This should "just work".

Is a.sh on your $PATH ?

If not, you need to invoke it with a path, e.g. ./a.sh

3 Comments

a.sh outputs date in some format, in b.sh he is doing: $(a.sh) which will take the output of date and try to execute it.
With proper formatting a lot more is visible :-) Drop the backticks, or do echo ./a.sh
Thanks a lot for the clarification.. so, this implies my understanding of backticks was not correct. Thanks for the help.
0

Try removing the backquotes from b.sh like below. this works for me.

#!/bin/bash

a.sh

exit

1 Comment

Thanks a lot for the clarification.. so, this implies my understanding of backticks was not correct. Thanks for the help.
0

The following lines in a.sh:

    echo `date`
    temp=`echo "$temp+1" | bc`

can be rewritten as:

    date
    : $(( temp += 1 ))

It seems that the root problem you are having is a misunderstanding of backticks, and you should understand why "echo `date`" is (almost) exactly the same as just "date" (they differ in whitespace only). The change I made to the second line is just personal preference (it is also more efficient).

1 Comment

Thanks a lot for the clarification.. so, this implies my understanding of backticks was not correct. Thanks for the help.

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.