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
Cannot Create Backup File(Add ! to Overwrite)
When Should the Option Remainafterexit Needs to Be Set True When Creating New Systemd Services
Execution Time of an SQLite Query: Units
Installing Qt on Linux, Cannot Find -Lgl
How to Check If Find Command Didn't Find Anything
How to Recursively Search for Files with Certain Extensions
How to Set Cap_Sys_Nice Capability to a Linux User
How to Add a String to the Beginning of Each File in a Folder in Bash
Linux Mail < File.Log Has Content-Type: Application/Octet-Stream (A Noname Attachment in Gmail)
Find Command in Bash Script Resulting in "No Such File or Directory" Error Only for Directories
Compile Swift Script with Static Swift Core Library
Start Rails Server Automatically When Ever I Start My Ubuntu MAChine
Is There a Clang Mingw Cross Compiler for Linux
Compressing the Core Files During Core Generation
Can't Install Freetds via Yum Package Manager