Parsing variables from config file in Bash

Since your config file is a valid shell script, you can source it into your current shell: . config_file echo “Content of VARIABLE1 is $VARIABLE1” echo “Content of VARIABLE2 is $VARIABLE2” echo “Content of VARIABLE3 is $VARIABLE3” Slightly DRYer, but trickier . config_file for var in VARIABLE1 VARIABLE2 VARIABLE3; do echo “Content of $var is … Read more

How to get the cursor position in bash?

You have to resort to dirty tricks: #!/bin/bash # based on a script from http://invisible-island.net/xterm/xterm.faq.html exec < /dev/tty oldstty=$(stty -g) stty raw -echo min 0 # on my system, the following line can be replaced by the line below it echo -en “\033[6n” > /dev/tty # tput u7 > /dev/tty # when TERM=xterm (and relatives) … Read more

Multi-line bash commands in makefile

You can use backslash for line continuation. However note that the shell receives the whole command concatenated into a single line, so you also need to terminate some of the lines with a semicolon: foo: for i in `find`; \ do \ all=”$$all $$i”; \ done; \ gcc $$all But if you just want to … Read more

Bash: Syntax error: redirection unexpected

Does your script reference /bin/bash or /bin/sh in its hash bang line? The default system shell in Ubuntu is dash, not bash, so if you have #!/bin/sh then your script will be using a different shell than you expect. Dash does not have the <<< redirection operator. Make sure the shebang line is: #!/bin/bash or … Read more

Trying to embed newline in a variable in Bash [duplicate]

Summary Inserting \n p=”${var1}\n${var2}” echo -e “${p}” Inserting a new line in the source code p=”${var1} ${var2}” echo “${p}” Using $’\n’ (only Bash and Z shell) p=”${var1}”$’\n'”${var2}” echo “${p}” Details Inserting \n p=”${var1}\n${var2}” echo -e “${p}” echo -e interprets the two characters “\n” as a new line. var=”a b c” first_loop=true for i in $var … Read more