2

I am trying to add a string to the end of a line using sed and regex.

I have the following string:

disable_functions = pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,

and im trying to add to the end of it the string:

exec,system,shell_exec,passthru,

My attempt is as follows:

sed -ie 's/disable_functions = .*[a-zA-z,]$/disable_functions = $1exec,system,shell_exec,passthru,/gI' /etc/php5/apache2/php.ini

It seems to just add $1 to the string disable_functions = $1exec,system,shell_exec,passthru,

Where am I going wrong?

2 Answers 2

2

Try that :

sed '/^disable_functions/s/$/exec,system,shell_exec,passthru,/' /etc/php5/apache2/php.ini

If the output seems OK, then add -i switch to modify the file.

$ here, mean end of line.

Sign up to request clarification or add additional context in comments.

Comments

1

Your original command is missing the capture group which sets the value of \1 (not $1):

sed -ie 's/disable_functions = \(.*[a-zA-z,])\$/disable_functions = \1exec,system,shell_exec,passthru,/gI' /etc/php5/apache2/php.ini

But as sputnick points out, you simply need to find the appropriate line and append the desired text; there's no need to match the old values and reinsert them.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.