help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-bash] Transform strings with special characters so that the string


From: Peng Yu
Subject: [Help-bash] Transform strings with special characters so that the strings don't need to be quoted?
Date: Tue, 24 Mar 2015 17:13:06 -0500

Hi,

Suppose that I have a variable with special characters, e.g, single
quote, double quote. How to transform the variable so that it can be
used without being quoted (for example "x'y" -> x\'y)?

One use case is something like the following. I want to construct a
diff command on the results of calling myscript on multiple files. The
following code works but not robustly with respect to any possible
filenames. Does anyone know the best solution in this case?

  cmd=diff
  for n
  do
    cmd="$cmd <(myscript '$n')"
  done
  eval "$cmd"

-- 
Regards,
Peng



reply via email to

[Prev in Thread] Current Thread [Next in Thread]