Having trouble trying to run this from bash :
[root@bryanserver ~]# $SPACER="#-------#" APACHE_ENABLED=`ls -1 "$HTTPD_HOSTS-EN" | grep ".conf" | sed s/.conf//` APACHE_COUNT=`echo -e "$APACHE_ENABLED" | wc -1` if [ -n "$APACHE_ENABLED" ]; then echo $SPACER echo "Apache enabled Sites: $APACHE_COUNT" echo "$APACHE_ENABLED" else echo $SPACER echo "There are no detectable nor delectable WebSites In Sight Blackbeard" fi
bash: syntax error near unexpected token `then
Is the problem with the code per se or with trying to use it from the shell rather than having it in a file and sourcing the file?
Entering this on the command line in Bash :
APACHE_ENABLED=`"$HTTPD_HOSTS_EN" | grep ".conf" | sed s/.conf//`
APACHE_COUNT=`echo -e "$APACHE_ENABLED" | wc -l`
if [ -n "$APACHE_ENABLED" ]; then
echo $SPACER
echo "Apache Enabled Sites: $APACHE_COUNT"
echo "$APACHE_ENABLED"
else
echo $SPACER
echo "There are no detected Apache Enabled Sites"
fi
produces this output:
APACHE_ENABLED=`"$HTTPD_HOSTS_EN" | grep ".conf" | sed s/.conf//`
APACHE_COUNT=`echo -e "$APACHE_ENABLED" | wc -l`
-bash: : command not found
[root@bryanserver ~]# APACHE_COUNT=`echo -e "$APACHE_ENABLED" | wc -l`
[root@bryanserver ~]# if [ -n "$APACHE_ENABLED" ]; then
> echo $SPACER
> echo "Apache Enabled Sites: $APACHE_COUNT"
> echo "$APACHE_ENABLED"
> else
> echo $SPACER
> echo "There are no detected Apache Enabled Sites"
> fi #
and hit enter and voila! this is the result: There are no detected Apache Enabled Sites [root@bryanserver ~]# and Bash is ready to do more work.
So, yes as Keith pointed out, I had mistaken an ell for a 1, and there are still some quirks, but it executes and issues a report. That's progress.
I am working here with some material from Charles Smith; he shared some scripts on GitHub; github.com/twohlix/HostingScripts/blob/master/listwww.
But I was using NotePad, and after editing some things, when I would put the text on the clipboard and unload it in Bash, what was I believe happening was I was getting the EOF issues. This SO question gave me an idea: bash EOF in if statement I used View / Show Line Endings in NotePad2, and copied my code, then pasted it into Bash, that worked.
SPACER=not$SPACER=at the beginning of the line. Also, you need either newlines or semicolons to seperate commands in yourifstatement.wc -l(lowercase letter ell) rather thanwc -1(digit one).