How to concatenate string variables in Bash
foo=”Hello” foo=”${foo} World” echo “${foo}” > Hello World In general to concatenate two variables you can just write them one after another: a=”Hello” b=’World’ c=”${a} ${b}” echo “${c}” > Hello World
foo=”Hello” foo=”${foo} World” echo “${foo}” > Hello World In general to concatenate two variables you can just write them one after another: a=”Hello” b=’World’ c=”${a} ${b}” echo “${c}” > Hello World
How can I check if a directory exists in a Bash shell script?
How do I execute a program or call a system command?
Here the way i was able to check it: ## function to install missing packages – $1 : package name. require_pkg() { if ! command -v $1 >/dev/null; then msg_warn missing_pkg $1 echo “Do you want to install $1 ? (works only with apt-get package manager) [y/N]” read -r YESNO if [[ $YESNO =~ ^([yY][eE][sS]|[yY])$ … Read more
AFAI understand you want to use an array: read -r -a names Example: read -r -a names <<< “John Marry Sanford Saunders” echo “${names[0]}” # John echo “${names[1]}” # Marry echo “${names[2]}” # Sanford echo “${names[3]}” # Saunders
[I] have tried everything … except, say: awk -F- ‘BEGIN { OFS=”-” } { sub(/[0-9]/,””,$3); print }’ yourdata
env sets one or more environment variables and then runs the remaining arguments as a command. It’s not significantly different from the following syntax: x='() { :;}; echo vulnerable’ bash -c “echo this is a test” One thing env can do (although the feature is not used in the above example) is create a clean … Read more
Before talking about redirections i have the feeling that you need to understand a basic thing: Linux commands produce normal output and error output, and unix gives you the freedom to “redirect” each output to a separate “channel” , called file descriptors (fd). Channel/fd 1 is used for std ouput and Channel/fd 2 is used … Read more
The algorithm to sort this problem is simple, just like you said in your question description, sort characters in each word first, then sort these sorted-word again. Like this: $ echo heya64 this is21 a good89 day91 | perl -anE ‘say(join ” “, sort(map { join “”, sort split // } @F))’ 12is 19ady 46aehy … Read more
You would use sed for a task like that. It supports a syntax like from lines matching AAA print everything up to and including a line matching XXX. Alas your input is a bit ill-formed because the starting pattern AAA occurs twice without a matching XXX for the second AAA. sed default behavior is to … Read more