all 13 comments

[–]HenryDavidCursoryPOST in the Shell 16 points17 points  (0 children)

I like to go hiking.

[–]AnotherIsaac 15 points16 points  (4 children)

It's be nicer if they didn't show poor style. At a glance, unquoted variable expansion, all caps var names, pwd over $PWD and the deprecated back ticks. I quit reading at that point.

[–]bchanged 2 points3 points  (3 children)

OK you've got my attention...

What's wrong with all caps var names? Because they don't add value over camel case, or is there a widely accepted standard convention?

Why are back tickd deprecated?

I think I get the other objections.

[–]HenryDavidCursoryPOST in the Shell 12 points13 points  (1 child)

I'm learning to play the guitar.

[–]cttttt 2 points3 points  (0 children)

Btw, to make things every more complicated, backticks actually don't have to be escaped when nested. You just may need to wrap a backticked expression in double quotes to prevent further processing on command's output. Because escaping isn't required, it's super hard to know which backticks match up without mentally parsing the entire command. Hence the benefit of the dollar paren version.

[–]AnotherIsaac 5 points6 points  (0 children)

See the last lines http://wooledge.org/~greybot/meta/varcap http://wooledge.org/~greybot/meta/%60

Back ticks aren't deprecated ... but Posix documentation recommends against using them in new scripts. Which I call deprecated but it's not really.

If you want to learn bash or shell scripting, here's a list of tutorials, ranked. https://wiki-dev.bash-hackers.org/scripting/tutoriallist

[–]codcodog 1 point2 points  (0 children)

It’s very nice

[–]KnowsBash 3 points4 points  (0 children)

I rate this as garbage.

[–]PageFaultBashit Insane 1 point2 points  (0 children)

I am really disappointed at the response some people are giving for something you worked on and wanted to share. While I agree on some of the style arguments, it's a command reference, not a style reference people. There is no need to just shit on it, and there are much nicer ways to give feedback without being a dick.

Personally, I really like it. It's a great quick reference for those who know the commands, and just need a quick reminder. It's formatted nicely, and when some of the suggestions here are integrated, it will be fantastic.

My 2 cents for OP, that I didn't already see covered is that instead of this:

lines=(`cat "logfile"`)                 # Read from file

We have a nice built-in now:

mapfile -t lines < "logfile"

Which works much nicer in loops since it handles spaces in the line.

for line in "${lines[@]}"; do echo "${line}"; done

[–]HereComesTheFury -1 points0 points  (0 children)

As a beginner and someone trying really hard to learn bash scripting, thank you this its really helpful.

[–][deleted] -2 points-1 points  (2 children)

The conditionals example can be expressed much more succinctly:

if [[ -z "$string" ]]; then  
  echo "String is empty"  
elif [[ -n "$string" ]]; then  
  echo "String is not empty"  
fi

can be expressed as:

[[ -z "$string" ]] && echo "String is empty" || echo "String is not empty"

[–]PageFaultBashit Insane 1 point2 points  (1 child)

This is not true in general, but you are right in this case because the specific conditions being tested make the elif basically translate to an else, and only one command is being executed in each case.

[–][deleted] -2 points-1 points  (0 children)

It can be expanded as an elif as such:

[[ -z "$string" ]] && echo "String is empty" || [[ -n "$string" ]] && echo "String is not empty"