I'm new to coding and trying to teach myself. I was wondering why I keep getting "notcoolbeans" instead of creating the directory?
if [ $mkdir /Users/Matt/Desktop/Yaya = 1 ];
echo "theres beans"
A correct implementation would look like this:
#!/bin/sh if mkdir /Users/Matt/Desktop/Yaya; then echo "theres beans" else echo "notcoolbeans" fi
Items of note:
!. (BTW, consider
#!/bin/shif you want a more full-featured scripting language).
[ ]is not part of the
ifstatement. It's a command that runs tests and sets exit status on output, but if you want to test the exit status of a different command, there's no call to use it.
$mkdiris trying to expand a variable named
mkdir. No such variable can be reasonably expected to exist in a new shell; if it's empty, then the result is
[ /Users/Matt/Desktop/Yaya = 1 ].
"1"are not identical strings, so this always fails.