1

I'm learning awk. Trying to do something useful with it by listing all hidden files in ls's long format:

alias llh="ls -la | awk '{ if ( $9 ~ /^\./ ) { print $0 }}'"

This is resulting in an error, however:

awk: cmd. line:1: { if ( ~ /^\./ ) { print -bash }} awk: cmd. line:1: ^ syntax error 

The $9 isn't showing in the error output. Maybe because it's empty? So I tried:

alias llh="ls -la | awk '{ if ( $9 && $9 ~ /^\./ ) { print $0 }}'"

Still no luck.

2
  • Yeah, looks like I'm in bash quote hell (again). Ugh. The command works fine when run directly on the command line. Commented Mar 27, 2019 at 18:20
  • OK, had to escape the variables in awk even when I had the entire alias value surrounded in single quotes. Which confuses me. I've got a severe mental block when it comes to bash quoting. Commented Mar 27, 2019 at 18:27

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.