Posts

Showing posts with the label sh

How can I make a function run every time cd successfully changes to another directory within sh on FreeBSD?

How can I make a function run every time cd successfully changes to another directory within sh on FreeBSD? I'm using sh as my shell on FreeBSD but I want to be able to have a pretty prompt like the one bash gives me on Ubuntu. There are two things that the FreeBSD implementation of sh seems to lack as far as PS1 escape characters go: The w works but does not expand $HOME to ~ , so this is something I have already hacked up myself w $HOME ~ I can use PS1 to update the prompt on the terminal, but as far as I can tell it is not possible to use the PS1 variable to update the title bar as well. ESC and BEL fail to set the title as one would expect if they were using bash or ksh ESC BEL Here is my .shrc file update_prompt() { case "$PWD" in "$HOME"*) pretty_pwd="~${PWD#*"${HOME}"}" ;; "/usr$HOME"*) pretty_pwd="~${PWD#*"/usr${HOME}"}" ;; *)...

Sed with Regexp not working?

Sed with Regexp not working? I'm trying to search in all files a text and replace it with the word EXAMPLE. I do the following: for f in /home/testu/zz*; do sed -i "s/&VAR1s*=s*'?[1]{4}'?/EXAMPLE/g" "$f" done It gives no error, the files seems to be "updated" in the filesystem, but they wont get changed. If I test that regexp with grep command it works fine, so it must be something about the regexp with the sed command but dunno what. Any help? Are you aware that [1]{4} matches 1111 ? Is that your intention? – Wiktor Stribiżew Jun 29 at 8:14 [1]{4} 1111 Ah, use sed -i "s/&VAR1s*=s*'?1{4}'?/EXAMPLE/g" or sed -i "s/&VAR1[[:blank:]]*=[[:blank:]]*'?1{4}'?/EXAMPLE/g" – Wiktor...