regexp search and replace for bash variables

خرید بک لینک

A number of my bash scripts need tidying up before sending them round. One of the thing I would like to do is to use curly braces for all variable names. So everywhere it says $PWD should be changed into ${PWD} et cetera.

As a test I use the code

PATH=${PWD}
PATH_PATH=$PATH
PATH_PATH_PATH=$PATH_PATH

My idea was to use regexp search and replace in emacs. The best expression that finds all my variable names (with CTRL-ALT-S) is $[A-Za-z0-9_-]*, so a sequence of 'a' through 'z', 'A' through 'Z', '0' through '9', underscore or hyphen following a '$'. Also, it leaves the already-braced variable names alone.

Now replace:
In the manual it says that replace is 'M-% string RET newstring RET'. On my computer 'M-%' is 'ESC-%'. Regexp replace is given as 'C-M-% regexp RET newstring RET'. I guess that would be C-ESC-% for me? Unfortunately, that is also the shortcut for the 'system activity' monitor in KDE.

I'm left with 2 questions now:

  1. is there another way to invoke regexp replace than C-ESC-%
  2. for the excmple above, what should be the expression for 'newstring'?

Recent Questions...

ما را در سایت Recent Questions دنبال می‌کنید

برچسب: نویسنده: استخدام کار بازدید: 226 تاريخ: پنجشنبه 23 ارديبهشت 1395 ساعت: 15:08

صفحه بندی