variable-expansion

What is the most elegant way to remove a path from the $PATH variable in Bash?

Or more generally, how do I remove an item from a colon-separated list in a Bash environment variable? I thought I had seen a simple way to do this years ago, using the more advanced forms of Bash variable expansion, but if so I've lost track of it. A quick search of Google turned up surprisingly few relevant results and none that I wo...

How to expand variables in vim commands?

I'm trying to get a variable expanded in a command call. Here's what I have in my .vimrc: command! -nargs=1 -complete=dir TlAddPm call s:TlAddPm(<f-args>) function! s:TlAddPm(dir) let flist = system("find " . shellescape(a:dir) . " -type f -name '*.pm' | sort") TlistAddFiles `=flist` endfun At the : prompt, the `=flist` syntax...

Batch file FOR/f expansion

I have a file (directories.txt) with directory names, each on a single line and I like to expand the line C:\Documents and Settings\%USERNAME%\My Documents In my script to the real user name running the script. However the echo comes out exactly the same as the line and %USERNAME% does not expand. FOR /f "tokens=*" %%X IN (directorie...

Bash quoting of current path (pwd)

Dear lazyweb, I have encountered a most annoying problem that occurs on the PWD variable when the current path includes a space. My code looks somewhat like this: mycommand |sed -E ' s|mystuff|replacement| ; s|'$(pwd)'|replacement| ; ' This works great, unless the current path contains a space character. If it does, $(pwd) i...

Replace variables in text: Suggestions?

I'm looking for a nice template engine or short piece of code to expand Ant-like variables in a string in Java. Example: String result = expand ("${firstName} ${familyName}", map); It should at least support java.util.Map but something that can handle beans or recursive lookups or lookups in a list of maps/objects would be welcome, to...

Expanding arbitrary variable to a drive, path etc. in a DOS batch

Hi. I am using a dos batch which processes file using passed parameter: process.bat "D:\PROJECT\TEST FILES\test.pdf" 72 process.bat: gswin32c -r%2 -sDEVICE=jpeg -sOutputFile="%~n1-%%d.jpg" -- "%~1" We can see that the parameter is expanded to the file name in the batch: %~n1. However I was asked to rewrite the batch to read parame...

bash: expanding variables with spaces

I have a file called "physics 1b.sh". In bash, if i try x="physics 1b" grep "string" "$x".sh grep complains: grep: physics 1b: No such file or directory. However, when I do grep "string" physics\ 1b.sh It works fine. So I guess the problem is something to do with the variable not being expanded to include the backslash that gr...

removing a case clause: bash expansion in sed regexp: X='a\.b' ; Y=';;' sed -n '/${X}/,/${Y}/d'

I'm trying to remove a case clause from a bash script. The clause will vary, but will always have backslashes as part of the case-match string. I was trying sed but could use awk or a perl one-liner within the bash script. The target of the edit is straightforward, resembles: $cat t.sh case N in a\.b); #[..etc., varies] ;; ...