Variable Syntax Error with Bash Script (Homework)

后端 未结 5 551
轻奢々
轻奢々 2020-12-11 11:07

I\'m currently working on homework for a Unix course and I\'ve got everything else done but I just can\'t figure out what I\'ve done wrong here. I\'ve done this exact same s

5条回答
  •  清歌不尽
    2020-12-11 11:35

    I indented the code for you. You have a few issues:

    • Always use quotation marks around echo statements. You can't use words like today's or else you're starting to quote everything to the end of your file.
    • Use indents. I indented your code as it appeared on my editor. Notice something? You're missing a fi to end an if statement.

    What type of system are you on? You should always use a real live program editor. I dope slap developers who use Notepad at my work.

    • You can always use VIM on any platform. It comes on Linux and Mac and is downloadable on Windows. Does automatic indenting and syntax highlighting which would have caught your incomplete if statement and your today's error.
    • VIM can be a bit daunting. It's powerful, but hard to learn. Notepad++ is a easy to use program editor with syntax highlighting and auto indenting.
    • On Mac, try TextWrangler which is free and includes syntax highlighting and auto indenting. You can also use Xcode which comes for free with Mac OS X.
    • On Linux, you're on your own. Most Linux people use either VIM, EMACs, or Eclipse. Kate is popular, but is a KDE application. I've seen a few people use BlueFish. Most are free, easy to install, and are open source.
    • A not so secret trick. Put set -xv in your code. It'll print out the lines being executed and the result once the shell interpolates that line. You can even set the PS4 prompt to \$LINENO: which will print out the line number of your shell script too. This is a great debugging aid. To turn off the verbose debugging, use set +xv.

提交回复
热议问题