0

I have this script:

!#/bin/bash

FOLDER=$('ls /var/lib/das/bi -ltr | grep 4096 | tail -1 | awk '{print $9}' ')
OUTPUT=${'. /var/lib/das/bi/$FOLDER/bi-uploader.sh'}
echo $OUTPUT

I have tried using \' to escape the quotes inside the awk, but it did not work. i get the error:

t $9}
awk: cmd. line:1: {print
awk: cmd. line:1:       ^ unexpected newline or end of string

./script.sh: line 5: ${'. /var/lib/everseen/bi/$FOLDER/bi-uploader.sh'}: bad substitution

How can i escape those quotes for the command to work?

Link
  • 361
  • 5
  • 17
  • 2
    Don't _escape_ the quotes. _Stop using_ the quotes. It's `outvar=$(command arg1 arg2 ...)`, not `outvar=$('command arg1 arg2 ...')`. You don't need to escape your inner quotes because you shouldn't _have_ outer quotes at all. – Charles Duffy Sep 18 '20 at 12:46
  • 1
    I closed this as a duplicate of a preexisting question that covers how to do what you asked for (putting literal single quotes inside a single-quoted string); but in the context of the code in this question, you shouldn't do what you asked for at all. – Charles Duffy Sep 18 '20 at 12:48
  • 1
    BTW, see [BashFAQ #99](https://mywiki.wooledge.org/BashFAQ/099) discussing more reliable ways to find the newest or oldest file in a directory. The `ls -ltr` approach is not something you want to actually use -- see also [Why you shouldn't parse the output of `ls`](https://mywiki.wooledge.org/ParsingLs) for more on that. – Charles Duffy Sep 18 '20 at 12:50

0 Answers0