I’m trying to do some manipulation with WordPress and I’m trying to write a script for it…
# cat /usr/local/uftwf/_wr.sh
#!/bin/sh
# $Id$
#
table_prefix=`grep ^\$table_prefix wp-config.php | awk -F\' '{print $2}'`
echo $table_prefix
#
Yet I’m getting following output
# /usr/local/uftwf/_wr.sh
ABSPATH ABSPATH wp-settings.php_KEY LOGGED_IN_KEY NONCE_KEY AUTH_SALT SECURE_AUTH_SALT LOGGED_IN_SALT NONCE_SALT wp_0zw2h5_ de_DE WPLANG WP_DEBUG s all, stop editing! Happy blogging. */
#
Running from command line, I get the correct output that I’m looking for:
# grep ^\$table_prefix wp-config.php | awk -F\' '{print $2}'
wp_0zw2h5_
#
What is going wrong in the script?
The problem is the
grepcommand:It either needs three backslashes – not one – or you need to use single quotes (which is much simpler):
It’s also worth using the
$( ... )notation in general.The trouble is that the backquotes removes the backslash, so the shell variable is evaluated, and what’s passed to
grepis, most likely, just^, and each line starts with a beginning of line.