how to escape $ (dollar sign) when echoing environment variable
by mfoley from LinuxQuestions.org on (#6MDF7)
I am looping through a list of files:
Code:#!/bin/bash
cat fileList | while read
do
ls "$REPLY"
doneThe problem is that some of the files have '$' signs, e.g. "dir/$this file". echo, and printf attempt to expand $this as an environment variable giving "dir/ file" which of course the ls command doesn't find.
Is there a way to preserve the '$'? I probably need to change that to "dir/\$this file". How can I do that?
Code:#!/bin/bash
cat fileList | while read
do
ls "$REPLY"
doneThe problem is that some of the files have '$' signs, e.g. "dir/$this file". echo, and printf attempt to expand $this as an environment variable giving "dir/ file" which of course the ls command doesn't find.
Is there a way to preserve the '$'? I probably need to change that to "dir/\$this file". How can I do that?