find “$(echo $HOME > variable_holder.txt && cat variable_holder.txt)/$(cat alphabet.txt | grep “d”) $(cat alphabet.txt | grep “o”)$(cat alphabet.txt | grep “c”)$(cat alphabet.txt | grep “s”)”
This is the easiest method
Submitted 1 year ago by zephyr@lemmy.world to programming@programming.dev
https://lemmy.world/pictrs/image/d6a45741-c5d4-4145-a27b-08b6217a083c.jpeg
find “$(echo $HOME > variable_holder.txt && cat variable_holder.txt)/$(cat alphabet.txt | grep “d”) $(cat alphabet.txt | grep “o”)$(cat alphabet.txt | grep “c”)$(cat alphabet.txt | grep “s”)”
This is the easiest method
no eval
?
This really enterprises my bash.
To be safe, should probably output grep to a file, then cat that.
when you’re paid by character written
What should I search to better understand what is written here? Don’t mind learning myself, just looking for the correct keywords. Thanks!
This comment is a joke and you wouldn’t want to do it like that in reality, but here are some related keywords you could look up: “Unix cat”, “Unix pipeline”, “grep”, “output redirection”, “command substitution”.
ExplainShell should help
Read the Bash manual. That one patter on the GP is called “Command Substitution”, you can search for it.
First one, then the other, then I forget the quotes, then I put them in single quotes by accident, then I utilize that “default value” colon syntax in case I’m missing HOME , then I just stick to ~ for the rest of the file.
I do what the linter tells me to: github.com/koalaman/shellcheck
Typically find “$HOME/docs”
, but with a few caveats:
In Zsh or Fish, the quotes are unnecessary: find $HOME/docs
If I’m using anything potentially destructive: mv “${HOME:?}/bin” …
thingsiplay@kbin.social 1 year ago
@zephyr
echo "${HOME}/docs"
bloopernova@programming.dev 1 year ago
This is the best way. It’s also the way the Shellcheck wants them.
thingsiplay@kbin.social 1 year ago
@bloopernova As you mention it, here the links for anyone interested: Online tool https://www.shellcheck.net/ and you can install it locally too https://github.com/koalaman/shellcheck .
gamma@programming.dev 1 year ago
Shellcheck doesn’t insist on braces unless it thinks you need them.
brennesel@feddit.de 1 year ago
This is the right way
drew_belloc@programming.dev 1 year ago
This is the way
Simulation6@sopuli.xyz 1 year ago
I also do this so the variables are more easily spotted.
gamma@programming.dev 1 year ago
This has never stuck with me, and I hadn’t thought about why until now. I have two reasons why I will always write
${x}_$y.z
instead of${x}_${y}.z
:$x_
being expanded as${x_}
.“$#array[3]”
actually prints the length of the third item inarray
, rather than (Bash:) the number of positional parameters, then the string‘array[3]’
.