0

Here's my script:

#!/bin/bash

path=$1

if [[ ./first.sh "$path" == "0" ]]
     echo "0"
fi

The script "first.sh" prints a number using echo. Now in the second script i wanna check if the output of the first script was "0" and if so, print "0"

What am I doing wrong?

1 Answer 1

1

If you want to read the output of a command/script run in shell, wrap it in $(). For example variable=$(ls "$path") reads the output of ls for the given path into variable.

Applying this to your problem

#!/bin/bash

path=$1
output=$(./first.sh "$path")
if [[ "$output" == "0" ]]; then
     echo "0"
fi

Please note that i also removed some errors (use ; then after the if statement).

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

2 Comments

thanks! is it possible to do something like this: if [[ $(ls -d */ "$path") = ""]]; then ? i wanna check if the path has no subdirectories
If you want to see if there is subdirectories, you can use find. Its a very usefull utility (check man7.org/linux/man-pages/man1/find.1.html). find "$path" -maxdepth 0 -type d | wc -l will give you the number of subdirectories. This should be 1 in case its empty, because only . will be returned for empty dirs.

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.