I'm new to stackoverflow and bash scripting, so go easy on me! I've been struggling with a bash script I've been writing: when I try to call a function 'main' from my script like so:
variable=$("main -t $path/$i")
I get the error "main -t ./folder: No such file or directory"; any ideas?
Thanks in advance!
EDIT: Thanks Jkbkot, I'm now calling it like this:
variable=$(main -t "$path/$i")
The original error is sorted but something is still up: 'variable' seemingly isn't being assigned the value echoed in the function, though calling the function manually prints the correct value. Why might this happen?
EDIT: It seems I'm calling and echoing correctly, but when calling 'main' it seems to behave differently when called recursively to the initial call. For example it runs fine up to:
variable=$(main -t "$path/$i") #A line within 'main'
Then begins again, as expected, but this time it stops as soon as it comes across a 'break', apparently breaking out of the entire function call rather that just the 'case' it's currently in. Is there some quirk to 'break' in bash that I'm unaware of?
NOTE: Unfortunately, the script is an assignment from my university, and many of its students and teachers use this website, so publicly posting my solution would likely have negative consequences.
#!/bin/bash main() { echo "$1-bar" } variable=$(main foo) echo $variableThe output isfoo-baras expected. Maybe your fucntion main outputs to stderr instead of stdout?echo VARIABLE:$variableto avoid any confusion output of which echo you see. Wrt stderr, you can try to redirect stderr to stdout:variable=$(main -t "$path/$i" 2>&1)If it works then your function outputs to stderr. Also, you can enable "debugging" by puttingset -xat the beginning of your script (on a line after the hashbang).