I don't know who
well, but a quick test reveals that it can contain /
characters, which is the delimiter you used for your sed
command. On my system, it did output something along the line of :
myName pts/0 2016-09-07 11:14 (10.123.45.678)
Notice the /
in pts/0
, that's what's breaking the sed
command, since it's its delimiter. Indeed, the following expanded sed
command contains a /
too many :
sed -i "5 s/I/myName pts/0 2016-09-07 11:14 (10.123.45.678)/" $1/$i/hello.txt
I think you could solve your problem by using the whoami
command instead, whose output probably correspond much better to what you expect:
$ whoami
myName
If you do want to use the output of who
, you will have either to escape the delimiter in the output of the who
command, or to use a delimiter that cannot be output by who
.
Assuming that who
will never output any +
character (I don't know if it's true, you should make sure !), you could use the following sed
command instead, where +
is used as a delimiter :
sed -i "5 s+I+$(who)+" $1/$i/hello.txt