I'm trying to edit a simple string in sed that I've been having issues with. Basically what I'm trying to do is grab my current working directory using pwd, pipe it to sed, edit the file path, then check the file paths contents using ls. The reason I need to do this is to dynamically check backups to see if backups contain the files I need in the folder that I'm currently working in (just going to make it into a quick hotkey).
Here's what I've got so far:
pwd | sed "s/`whoami`/`whoami`.{daily,weekly,monthly}/g" | xargs ls
When running this on my server (it's a shared hosting server, hence the need for whoami
instead of just username) I get this error:
/bin/ls: cannot access /home1/username.{daily,weekly,monthly}: No such file or directory
However, I'm able to run this command without any issues:
ls /home1/username.{daily,weekly,monthly}
I've tried probably ~20 different variations of this command (various sed and xargs flags as well) and can't seem to get it to work properly. I believe this error is being caused by how sed handles the search and replace with streams, however I don't know how to get around it or what exactly it is that's causing it.
I believe it's sed that's causing the issue as this command has the same error:
ls `pwd | sed "s/$(whoami)/$(whoami).{daily,weekly,monthly}/g"`
/bin/ls: cannot access /home1/username.{daily,weekly,monthly}: No such file or directory
If anyone can tell me why it's happening, or some way for sed to properly pass the edited version to ls. I should be able to figure out a command for it, I just need to know why. Thanks!