0

I am looking for a sed command in linux to add a line to multiple .bashrc files in a directory, but want it to adjust for the username.

directory: /home/user/
sub directory 1: /fredr/
sub directory 2: /jimw/
file under sub directory: .bashrc
line to add: export KDEVARTMP=/home/user/${user}/ 

But I want the ${user} to change for each sub directory it goes into, e.g.

export KDEVARTMP=/home/user/fredr/ 

and am not looking to replace any lines, only append this line to the bottom the .bashrc file of that user.

There are over 100 users in the user directory and want to just apply this updated line to all of them at once.

2
#!/bin/bash

for udir in /home/user/*; do
        echo "export KDEVARTMP='$udir'" >> "$udir"/.bashrc
done;

Not with sed as you asked but will do the job.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.