[CentOS] bash off topic

Paul Heinlein heinlein at madboa.com
Thu May 16 17:22:35 UTC 2019


On Thu, 16 May 2019, Jerry Geis wrote:

> I have a simple bash script it will take arguments from a file that has
> quotes.
>
> my file arg.txt would be this
> -lt "*.txt"
>
> my script file would be
> LS_ARG=`cat arg.txt`
> ls $LS_ARG
>
> it does not run properly:
> sh -x ./arg.sh
> ++ cat arg.txt
> + LS_ARG='-lt "*.txt"'
> + ls -lt '"*.txt"'
> ls: cannot access "*.txt": No such file or directory
>
>
> How do I resolve that ?  If the quotes are not in my file it all works
> fine. I think its because it looks like the extra single quotes it puts
> around the "*.txt" - or - '"*.txt"'  - how do I do this ?  This is just a
> short example of my larger need.

In general, shell utilities won't expand a wildcard within quotes 
(double or single). As I think you've discovered, this works fine:

echo '-lt *.txt' > argfile
ls $(< argfile)

I think you're going to need to provide a test case where the quotes 
are actually required.

-- 
Paul Heinlein
heinlein at madboa.com
45°38' N, 122°6' W


More information about the CentOS mailing list