Reputation: 23
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.
Upvotes: 2
Views: 241
Reputation: 7571
You have to call it without the quotes:
variable=$(main -t $path/$i)
and as @janos says, you might need the quotes around the variables in case they might contain spaces, etc.:
variable=$(main -t "$path/$i")
Upvotes: 5