I am facing problems running two commands one after another in bash. When I run
source2() { '/home/ds/Documents/scripts/Untitled Document 1.sh' && imgpath="$(ls | grep "^unsplash")" }
source3() { '/home/ds/Documents/scripts/Untitled Document 2.sh' && imgpath="$(ls | grep "^1920x1080" | shuf -n 1)" }
source4() { '/home/ds/Documents/scripts/Untitled Document 3.sh' && imgpath="$(ls | grep "^unsplashimg")" }
SOURCES=("source2" "source3" "source4")
$(eval $(shuf -n1 -e "${SOURCES[@]}"))
echo $imgpath
The bash script part runs, but the part after &&
does not
and hence echo $imgpath
gives no output. When I run individual commands like
'/home/ds/Documents/scripts/Untitled Document 1.sh' && imgpath="$(ls | grep "^unsplash")"
then I get desired outputs.
What am I doing wrong?
I have taken hints from
;
to allow correct parsing of the following}