How to Set Environment Variables in My Linux Service for Asterisk Even Though It Doesn't Have a Real User

How can I set environment variables in my Linux service for Asterisk even though it doesn't have a real user?

Either set them in the startup script (/etc/init.d/yourdaemon), or put a line in that file that looks like:

. /etc/yourdaemon.env

and put the environment variables in that file, using the syntax export VAR=value. On Red Hat-like systems, I believe the correct place for such a file is /etc/sysconfig. Debian/Ubuntu seems to have /etc/default for this purpose.

How to export variable which includes * (asterisk) sign in it?

Your export command is okay and does not cause the asterisks to be expanded. The problem is your echo $TEST. The rules for POSIX shells cause the expansion of $TEST to occur before glob expansion. So what you are doing is actually this:

echo 30 *

If you quote the expansion to inhibit the glob expansion you will see what you expect:

echo "$TEST"

Your question is a good example why the POSIX 1003 shell behavior is awful. And so many new, innovative, shells like fish and elvish don't implement that behavior.

Linux service can't load library path in the /etc/ld.so.conf.d

Did you run ldconfig (as root) lately? There's a shared library cache that's updated by that program, and if you updated a file in /etc/ld.so.conf.d without running ldconfig, the cache data could be out of date.

How do I escape the wildcard/asterisk character in bash?

Quoting when setting $FOO is not enough. You need to quote the variable reference as well:

me$ FOO="BAR * BAR"
me$ echo "$FOO"
BAR * BAR

How to run the shellscript with -z parameters?

With

test -z "$MONGODB_PASSWORD"

you are testing if the variable $MONGODB_PASSWORD is not empty.

Before running the script you will have to store your password in the variable:

MONGODB_PASSWORD="password" ./init.sh

Bash - export environment variables with special characters ($)

You don't need eval at all, just use declare built-in in bash to create variables on-the-fly!

case "$key" in
'#'*) ;;
*)
declare $key=$value
export "$key"
esac


Related Topics



Leave a reply



Submit