benjist
benjist

Reputation: 2881

Bash: "Invalid option" when run in bash script, fine on console

The following works on console, but throws an "invalid option" when run as part of a bash script.

styles=find . -type d -maxdepth 1 | awk -F/ {'print $NF'}
line x: .: -t: invalid option

Upvotes: 0

Views: 5218

Answers (1)

heemayl
heemayl

Reputation: 41987

To save the output of a command to a variable, you need to use command substitution:

styles="$(find . -maxdepth 1 -type d | awk -F/ '{print $NF}')"

Upvotes: 2

Related Questions