[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Tilde expansion in awk pipes
From: |
limited time |
Subject: |
Tilde expansion in awk pipes |
Date: |
Sun, 6 Oct 2024 03:01:35 +0530 |
Hello, there seem to be some situations where tilde expansion does not work as
usual.
BEGIN {
"set -x ; echo ~'/path/to/file'" | getline output1
"set -x ; echo ~''" | getline output2
"set -x ; echo ~\"/path/to/file\"" | getline output3
print output1
print output2
print output3
}
Running this script :-
❯ gawk -f script.awk
+ echo '~/path/to/file'
+ echo '~'
+ echo '~/path/to/file'
~/path/to/file
~
~/path/to/file
The set -x command turns on xtracing in zsh and it shows that awk is quoting
the tilde sign.
All three forms work in the interactive shell :-
❯ echo ~'/path/to/file' ; echo ~'' ; echo ~"/path/to/file"
/Users/username/path/to/file
/Users/username
/Users/username/path/to/file
Is this by design ? The below three forms also work as usual :-
BEGIN {
"set -x ; echo ~" | getline output1
"set -x ; echo ~/'path/to/file'" | getline output2
"set -x ; echo ~/\"path/to/file\"" | getline output3
print output1
print output2
print output3
}
❯ gawk -f script.awk
+ echo /Users/username
+ echo /Users/username/path/to/file
+ echo /Users/username/path/to/file
/Users/username
/Users/username/path/to/file
/Users/username/path/to/file
- Tilde expansion in awk pipes,
limited time <=