idank / explainshell

match command-line arguments to their help text
GNU General Public License v3.0
12.98k stars 778 forks source link

Useless use of echo #292

Closed Strahinja closed 2 years ago

Strahinja commented 2 years ago

One of the examples on the front page,

file=$(echo `basename "$file"`)

is a useless use of echo, and could be rewritten as

file=$(basename "$file")

or, just using parameter expansion in POSIX shell, without the need for an external program:

file=${file#*/}; file=${file%.*}
idank commented 2 years ago

It's just an example to illustrate the capabilities, feel free to send a PR to change it.

Strahinja commented 2 years ago

Nevertheless, since explainshell.com is likely to be used for learning shell, it potentially teaches bad habits. Another issue with that example is the use of backticks, which are deprecated in favor of the parenthesized form $() of command substitution. I will offer an alternative example in a PR.

Update: I submitted the PR.