i need to “answer something” for “certain names” in bash shell
thanks!!
Sorry to write here but its the only place i know, is there a good place to learn these things? i tried discord but i could not write there, sorry im super noob, i dont have any studies or experience ( know how to make folder or copy file on konsole ) i really like it !
Well, you don’t show us the question, so we can only guess.
Regardless, don’t have other people give you answers to questions. Rather, go look for them yourself. There’s a whole internet to help you, if, and only if you look for things yourself, try them, test them, and learn (from) them.
Everything in Linux is documented in man pages, so you can man bash at the command line. Some documentation can be found in “/usr/share/doc/package”. Replace package with bash. This documentation may be the same as the man page, but in a different format. There are many sites that host man pages, here’s Arch Linux man pages.
If you query a package like, pacman -Qi bash, you will find the URL or home of the package. In this case, Bash - GNU Project - Free Software Foundation. You will find more documentation at a package home.
youtube is your friend. Old Tech Bloke is well done and covers various aspects of distros so you can learn the lingo in context, but you can also find videos on specific topics.
Two-fer or 2-fer is short for two for one. One for you and one for me.
Given a name, return a string with the message:
One for name, one for me.
Where “name” is the given name.
However, if the name is missing, return the string:
One for you, one for me.
Here are some examples:
Name String to return
Alice One for Alice, one for me.
Bob One for Bob, one for me.
Me/Self One for you, one for me.
Zaphod One for Zaphod, one for me.
!/bin/bash
declare -- name=''
while read -r name; do
if [[ -z "${name}" ]]; then
name='you'
fi
printf -- 'One for %s, one for me\n' "${name}"
done <<EOF
Alice
Bob
Zaphold
EOF
The control structure could also have been
for name in 'Alice' 'Bob' '' 'Zaphold'; do
:
done
Some take aways:
quoting
double
single
printf instead of echo
-- after printf
[[ ]] instead of [ ]
the test operator -z
type help test to view more
On the command line you can get short help for bash, like: help if, help for, help printf.
When you want to learn more about a command, type -a. Try type -a [ and type -a [[. Notice one says shell keyword and the other shell builtin. Also type -a : .
Definitely look the above items up in the bash man page/documentation to learn more.