Reputation:
i have a sh-Script with:
#!/bin/sh
dirs=( $(find . -maxdepth 1 -type d -printf '%P\n') )
echo "There are ${#dirs[@]} dirs in the current path"
let i=1
for dir in "${dirs[@]}"; do
echo "$((i++)) $dir"
done
answer=2
echo "you selected ${dirs[$answer]}!"
But i got the error:
symfonymenu.sh: Syntax error: "(" unexpected (expecting "}")
its the line ...dirs=
I like to echo all available directories in a folder that user can select it in a prompt interface.
Upvotes: 0
Views: 72
Reputation: 111259
You use features from the bash shell, so you should execute the script in bash. Change the first line to:
#!/bin/bash
/bin/sh
can be any POSIX-compatible shell, for example on Ubuntu it's dash.
Upvotes: 3
Reputation: 75488
That's a bash script so you should make sure that you're running it with bash
. Call it as bash script.sh
. Also you should start your index from 0 not 1: let i=0
.
Upvotes: 2