expected fi bug in bash script
The following bash script creates a directory if not exists and writes a file to it. Now, if directory exists, it retrieves a list of files of this directory encapsulated in an array. This is the code:
if [ -d $ETC_DIR ]; then
echo " * wan27 has been found on your system"
echo " * checking for installed versions"
versions=( `ls $ETC_DIR` ) # line 27
else
echo " * First time installation! Creating etc directory now..."
mkdir $ETC_DIR
echo "$VERSION\n$USERi\n`date +%Y%m%d%H%M%S`\n$ROOT_DIR" > $ETC_DIR/install_$VERSION.txt
fi
And this is what the terminal outputs:
27: Syntax error: "(" unexpected (expecting "fi")
So, line 27 actually is this one in first excerpt of code:
versions=( `ls $ETC_DIR` )
What am I doing wrong? I've tried added semi-colons as well bu开发者_如何学Pythont ended up with the same result...
Your script relies on a Bash feature (creating an array using assignment with parentheses), but it's being run by the Bourne shell.
Change the first line of your script to:
#!/bin/bash
精彩评论