Bash awk command with quotesHow to escape quotes in shell?Bash script with quotes and spacesBash - Command substitution adds single quotesIs it possible to print an iterated range of arguments via cli from a csv? (see example)How to pass string with special characters to shell command in a script?Saving command output to a variable in bash results in “Unescaped left brace in regex is deprecated”How Do I Unbuffer The Output Passed From an Interactive Command Into a Pipeline Ending With `tee`?bash escaping quotes“sudo -s <command>” runs command in a shell, but wildcards or metacharacters not working
What does "boys rule, girls drool" mean?
ColorFunction based on array index in ListLinePlot
Why is the Digital 0 not 0V in computer systems?
What is a "major country" as named in Bernie Sanders' Healthcare debate answers?
Is there any reason to concentrate on the Thunderous Smite spell after using its effects?
Permutations in Disguise
Are space camera sensors usually round, or square?
Can I conceal an antihero's insanity - and should I?
If I want an interpretable model, are there methods other than Linear Regression?
super and subscripts on stackrel variable
Why don't Wizards use wrist straps to protect against disarming charms?
Absolutely wonderful numerical phenomenon. Who can explain?
If a space ship entered Earth orbit, how likely is it to be seen?
In what state are satellites left in when they are left in a graveyard orbit?
Bash awk command with quotes
Olympic game scoring
Does my opponent need to prove his creature has morph?
What 68-pin connector is this on my 2.5" solid state drive?
How do I say "quirky" in German without sounding derogatory?
Why is my fire extinguisher emptied after one use?
Add text inside circuit component in circuitikz environment
80s sci fi film with line "Paris? Bye bye!"
How would you control supersoldiers in a late iron-age society?
What organs or modifications would be needed for a life biological creature not to require sleep?
Bash awk command with quotes
How to escape quotes in shell?Bash script with quotes and spacesBash - Command substitution adds single quotesIs it possible to print an iterated range of arguments via cli from a csv? (see example)How to pass string with special characters to shell command in a script?Saving command output to a variable in bash results in “Unescaped left brace in regex is deprecated”How Do I Unbuffer The Output Passed From an Interactive Command Into a Pipeline Ending With `tee`?bash escaping quotes“sudo -s <command>” runs command in a shell, but wildcards or metacharacters not working
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have been trying to find the answer to this question for awhile. I am writing a quick script to run a command based on output from awk.
ID_minimum=1000
for f in /etc/passwd;
do awk -F: -vID=$ID_minimum '$3>=1000 && $1!="nfsnobody" print "xfs_quota -x -c 'limit bsoft=5g bhard=6g $1' /home "' $f;
done
The problems are that the -c argument takes a command in single quotes and I can't figure out how to properly escape that and also that $1 doesn't expand into the username.
essentially I am just trying to get it to output:
xfs_quota -x -c 'limit bsoft=5g bhard=6g userone' /home
xfs_quota -x -c 'limit bsoft=5g bhard=6g usertwo' /home
etc...
bash shell scripting
New contributor
|
show 2 more comments
I have been trying to find the answer to this question for awhile. I am writing a quick script to run a command based on output from awk.
ID_minimum=1000
for f in /etc/passwd;
do awk -F: -vID=$ID_minimum '$3>=1000 && $1!="nfsnobody" print "xfs_quota -x -c 'limit bsoft=5g bhard=6g $1' /home "' $f;
done
The problems are that the -c argument takes a command in single quotes and I can't figure out how to properly escape that and also that $1 doesn't expand into the username.
essentially I am just trying to get it to output:
xfs_quota -x -c 'limit bsoft=5g bhard=6g userone' /home
xfs_quota -x -c 'limit bsoft=5g bhard=6g usertwo' /home
etc...
bash shell scripting
New contributor
1
Possible duplicate of How to escape quotes in shell?
– jordanm
9 hours ago
2
Your loop only ever iterates once.
– jordanm
9 hours ago
@jordanm I don't think that applies toawk
– Jesse_b
9 hours ago
2
@Jesse_b his quoting issue is shell quoting, doesn't really have anything to do with awk. He needs to escape nested single quotes.
– jordanm
9 hours ago
1
Related: How to escape a single quote inside awk
– Freddy
9 hours ago
|
show 2 more comments
I have been trying to find the answer to this question for awhile. I am writing a quick script to run a command based on output from awk.
ID_minimum=1000
for f in /etc/passwd;
do awk -F: -vID=$ID_minimum '$3>=1000 && $1!="nfsnobody" print "xfs_quota -x -c 'limit bsoft=5g bhard=6g $1' /home "' $f;
done
The problems are that the -c argument takes a command in single quotes and I can't figure out how to properly escape that and also that $1 doesn't expand into the username.
essentially I am just trying to get it to output:
xfs_quota -x -c 'limit bsoft=5g bhard=6g userone' /home
xfs_quota -x -c 'limit bsoft=5g bhard=6g usertwo' /home
etc...
bash shell scripting
New contributor
I have been trying to find the answer to this question for awhile. I am writing a quick script to run a command based on output from awk.
ID_minimum=1000
for f in /etc/passwd;
do awk -F: -vID=$ID_minimum '$3>=1000 && $1!="nfsnobody" print "xfs_quota -x -c 'limit bsoft=5g bhard=6g $1' /home "' $f;
done
The problems are that the -c argument takes a command in single quotes and I can't figure out how to properly escape that and also that $1 doesn't expand into the username.
essentially I am just trying to get it to output:
xfs_quota -x -c 'limit bsoft=5g bhard=6g userone' /home
xfs_quota -x -c 'limit bsoft=5g bhard=6g usertwo' /home
etc...
bash shell scripting
bash shell scripting
New contributor
New contributor
edited 9 hours ago
Jesse_b
18.8k3 gold badges46 silver badges88 bronze badges
18.8k3 gold badges46 silver badges88 bronze badges
New contributor
asked 9 hours ago
ZCTZCT
162 bronze badges
162 bronze badges
New contributor
New contributor
1
Possible duplicate of How to escape quotes in shell?
– jordanm
9 hours ago
2
Your loop only ever iterates once.
– jordanm
9 hours ago
@jordanm I don't think that applies toawk
– Jesse_b
9 hours ago
2
@Jesse_b his quoting issue is shell quoting, doesn't really have anything to do with awk. He needs to escape nested single quotes.
– jordanm
9 hours ago
1
Related: How to escape a single quote inside awk
– Freddy
9 hours ago
|
show 2 more comments
1
Possible duplicate of How to escape quotes in shell?
– jordanm
9 hours ago
2
Your loop only ever iterates once.
– jordanm
9 hours ago
@jordanm I don't think that applies toawk
– Jesse_b
9 hours ago
2
@Jesse_b his quoting issue is shell quoting, doesn't really have anything to do with awk. He needs to escape nested single quotes.
– jordanm
9 hours ago
1
Related: How to escape a single quote inside awk
– Freddy
9 hours ago
1
1
Possible duplicate of How to escape quotes in shell?
– jordanm
9 hours ago
Possible duplicate of How to escape quotes in shell?
– jordanm
9 hours ago
2
2
Your loop only ever iterates once.
– jordanm
9 hours ago
Your loop only ever iterates once.
– jordanm
9 hours ago
@jordanm I don't think that applies to
awk
– Jesse_b
9 hours ago
@jordanm I don't think that applies to
awk
– Jesse_b
9 hours ago
2
2
@Jesse_b his quoting issue is shell quoting, doesn't really have anything to do with awk. He needs to escape nested single quotes.
– jordanm
9 hours ago
@Jesse_b his quoting issue is shell quoting, doesn't really have anything to do with awk. He needs to escape nested single quotes.
– jordanm
9 hours ago
1
1
Related: How to escape a single quote inside awk
– Freddy
9 hours ago
Related: How to escape a single quote inside awk
– Freddy
9 hours ago
|
show 2 more comments
4 Answers
4
active
oldest
votes
To run the command xfs_quota -x -c 'limit bsoft=5g bhard=6g USER' /home
for each USER
whose UID is at least $ID_minimum
, consider parsing out those users first and then actually run the command, rather than trying to create a string representing the command that you want to run.
If you create the command string, you would have to eval
it. This is fiddly and easy to get wrong. It's better to just get a list of usernames and then to run the command.
getent passwd |
awk -F: -v min="$ID_minimum:-1000" '$3 >= min && $1 != "nfsnobody" print $1 ' |
while IFS= read -r user; do
xfs_quota -x -c "limit bsoft=5g bhard=6g $user" /home
done
Note that there is no actual need for single quotes around the argument after -c
. Here I use double quotes because I want the shell to expand the $user
variable which contains values extracted by awk
.
I use $ID_minimum:-1000
when giving the value to the min
variable in the awk
command. This will expand to the value of $ID_minimum
, or to 1000
if that variable is empty or not set.
the only answer to correctly use getent rather than parse /etc/passwd.
– cas
4 hours ago
add a comment
|
for f in /etc/passwd;
This is a bit silly as there's really no loop with just one value.
But the issue seems to be printing single quotes from awk. You could escape them in the shell, but you could also use backslash-escapes within awk to print them. OOO
is the character with numerical value OOO (in octal), so 47
is '
. So this would be one way to do it:
awk -F: -vID=$ID_minimum '$3>=1000 && $1!="nfsnobody"
printf "xfs_quota -x -c 47limit bsoft=5g bhard=6g %s47 /homen", $1' /etc/passwd
You could use the similar escape in hex, x27
, but it can get misinterpreted in some implementations if the following character is a valid hexadecimal digit. (And of course I assumed ASCII or an ASCII-compatible character set, e.g. UTF-8.)
Note that it's fine here asl
is not a hex digit, but"x27dfn"
would be treated as"x27" "df"
in busybox awk or mawk but as"xdf"
(0x27df
cast to 8 bit char) in the original awk and gawk (that's the reason why POSIX doesn't specifyxHH
). Octals (47
) don't that the same problem and are POSIX. In any case, that assumes an ASCII system (a reasonable assumption these days).
– Stéphane Chazelas
8 hours ago
add a comment
|
Use the -f -
option to awk to take the script from stdin and a here-document:
awk -F: -v "ID=$ID_minimum" -f - <<'EOT' /etc/passwd
$3>=1000 && $1!="nfsnobody"
print "xfs_quota -x -c 'limit bsoft=5g bhard=6g "$1"' /home "
EOT
add a comment
|
This did it.
awk -F: -vID=$ID_minimum '$3>=1000 && $1!="nfsnobody" print "xfs_quota -x -c '"'"'limit bsoft=5g bhard=6g ''"$1"'''"'"' /home "' /etc/passwd
New contributor
Yo dawg I heard you like quotes...
– Jesse_b
9 hours ago
@Jesse_b, yes, you can't put single quotes inside a single-quoted string, so you have to end it first, and then quote the single quote you want to insert. It doesn't matter if you do'''
or'"'"'
. Both work, both look annoying.
– ilkkachu
9 hours ago
1
@ilkkachu: It was a joke in the theme of the xzibit meme.
– Jesse_b
9 hours ago
@OP, hopefully you saw jordanm's comment about your loop being unnecessary. Your loop is only ever run once so it's not different than simply running the same awk command outside of a loop.
– Jesse_b
9 hours ago
add a comment
|
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
ZCT is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f541632%2fbash-awk-command-with-quotes%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
To run the command xfs_quota -x -c 'limit bsoft=5g bhard=6g USER' /home
for each USER
whose UID is at least $ID_minimum
, consider parsing out those users first and then actually run the command, rather than trying to create a string representing the command that you want to run.
If you create the command string, you would have to eval
it. This is fiddly and easy to get wrong. It's better to just get a list of usernames and then to run the command.
getent passwd |
awk -F: -v min="$ID_minimum:-1000" '$3 >= min && $1 != "nfsnobody" print $1 ' |
while IFS= read -r user; do
xfs_quota -x -c "limit bsoft=5g bhard=6g $user" /home
done
Note that there is no actual need for single quotes around the argument after -c
. Here I use double quotes because I want the shell to expand the $user
variable which contains values extracted by awk
.
I use $ID_minimum:-1000
when giving the value to the min
variable in the awk
command. This will expand to the value of $ID_minimum
, or to 1000
if that variable is empty or not set.
the only answer to correctly use getent rather than parse /etc/passwd.
– cas
4 hours ago
add a comment
|
To run the command xfs_quota -x -c 'limit bsoft=5g bhard=6g USER' /home
for each USER
whose UID is at least $ID_minimum
, consider parsing out those users first and then actually run the command, rather than trying to create a string representing the command that you want to run.
If you create the command string, you would have to eval
it. This is fiddly and easy to get wrong. It's better to just get a list of usernames and then to run the command.
getent passwd |
awk -F: -v min="$ID_minimum:-1000" '$3 >= min && $1 != "nfsnobody" print $1 ' |
while IFS= read -r user; do
xfs_quota -x -c "limit bsoft=5g bhard=6g $user" /home
done
Note that there is no actual need for single quotes around the argument after -c
. Here I use double quotes because I want the shell to expand the $user
variable which contains values extracted by awk
.
I use $ID_minimum:-1000
when giving the value to the min
variable in the awk
command. This will expand to the value of $ID_minimum
, or to 1000
if that variable is empty or not set.
the only answer to correctly use getent rather than parse /etc/passwd.
– cas
4 hours ago
add a comment
|
To run the command xfs_quota -x -c 'limit bsoft=5g bhard=6g USER' /home
for each USER
whose UID is at least $ID_minimum
, consider parsing out those users first and then actually run the command, rather than trying to create a string representing the command that you want to run.
If you create the command string, you would have to eval
it. This is fiddly and easy to get wrong. It's better to just get a list of usernames and then to run the command.
getent passwd |
awk -F: -v min="$ID_minimum:-1000" '$3 >= min && $1 != "nfsnobody" print $1 ' |
while IFS= read -r user; do
xfs_quota -x -c "limit bsoft=5g bhard=6g $user" /home
done
Note that there is no actual need for single quotes around the argument after -c
. Here I use double quotes because I want the shell to expand the $user
variable which contains values extracted by awk
.
I use $ID_minimum:-1000
when giving the value to the min
variable in the awk
command. This will expand to the value of $ID_minimum
, or to 1000
if that variable is empty or not set.
To run the command xfs_quota -x -c 'limit bsoft=5g bhard=6g USER' /home
for each USER
whose UID is at least $ID_minimum
, consider parsing out those users first and then actually run the command, rather than trying to create a string representing the command that you want to run.
If you create the command string, you would have to eval
it. This is fiddly and easy to get wrong. It's better to just get a list of usernames and then to run the command.
getent passwd |
awk -F: -v min="$ID_minimum:-1000" '$3 >= min && $1 != "nfsnobody" print $1 ' |
while IFS= read -r user; do
xfs_quota -x -c "limit bsoft=5g bhard=6g $user" /home
done
Note that there is no actual need for single quotes around the argument after -c
. Here I use double quotes because I want the shell to expand the $user
variable which contains values extracted by awk
.
I use $ID_minimum:-1000
when giving the value to the min
variable in the awk
command. This will expand to the value of $ID_minimum
, or to 1000
if that variable is empty or not set.
edited 8 hours ago
answered 8 hours ago
Kusalananda♦Kusalananda
164k19 gold badges321 silver badges508 bronze badges
164k19 gold badges321 silver badges508 bronze badges
the only answer to correctly use getent rather than parse /etc/passwd.
– cas
4 hours ago
add a comment
|
the only answer to correctly use getent rather than parse /etc/passwd.
– cas
4 hours ago
the only answer to correctly use getent rather than parse /etc/passwd.
– cas
4 hours ago
the only answer to correctly use getent rather than parse /etc/passwd.
– cas
4 hours ago
add a comment
|
for f in /etc/passwd;
This is a bit silly as there's really no loop with just one value.
But the issue seems to be printing single quotes from awk. You could escape them in the shell, but you could also use backslash-escapes within awk to print them. OOO
is the character with numerical value OOO (in octal), so 47
is '
. So this would be one way to do it:
awk -F: -vID=$ID_minimum '$3>=1000 && $1!="nfsnobody"
printf "xfs_quota -x -c 47limit bsoft=5g bhard=6g %s47 /homen", $1' /etc/passwd
You could use the similar escape in hex, x27
, but it can get misinterpreted in some implementations if the following character is a valid hexadecimal digit. (And of course I assumed ASCII or an ASCII-compatible character set, e.g. UTF-8.)
Note that it's fine here asl
is not a hex digit, but"x27dfn"
would be treated as"x27" "df"
in busybox awk or mawk but as"xdf"
(0x27df
cast to 8 bit char) in the original awk and gawk (that's the reason why POSIX doesn't specifyxHH
). Octals (47
) don't that the same problem and are POSIX. In any case, that assumes an ASCII system (a reasonable assumption these days).
– Stéphane Chazelas
8 hours ago
add a comment
|
for f in /etc/passwd;
This is a bit silly as there's really no loop with just one value.
But the issue seems to be printing single quotes from awk. You could escape them in the shell, but you could also use backslash-escapes within awk to print them. OOO
is the character with numerical value OOO (in octal), so 47
is '
. So this would be one way to do it:
awk -F: -vID=$ID_minimum '$3>=1000 && $1!="nfsnobody"
printf "xfs_quota -x -c 47limit bsoft=5g bhard=6g %s47 /homen", $1' /etc/passwd
You could use the similar escape in hex, x27
, but it can get misinterpreted in some implementations if the following character is a valid hexadecimal digit. (And of course I assumed ASCII or an ASCII-compatible character set, e.g. UTF-8.)
Note that it's fine here asl
is not a hex digit, but"x27dfn"
would be treated as"x27" "df"
in busybox awk or mawk but as"xdf"
(0x27df
cast to 8 bit char) in the original awk and gawk (that's the reason why POSIX doesn't specifyxHH
). Octals (47
) don't that the same problem and are POSIX. In any case, that assumes an ASCII system (a reasonable assumption these days).
– Stéphane Chazelas
8 hours ago
add a comment
|
for f in /etc/passwd;
This is a bit silly as there's really no loop with just one value.
But the issue seems to be printing single quotes from awk. You could escape them in the shell, but you could also use backslash-escapes within awk to print them. OOO
is the character with numerical value OOO (in octal), so 47
is '
. So this would be one way to do it:
awk -F: -vID=$ID_minimum '$3>=1000 && $1!="nfsnobody"
printf "xfs_quota -x -c 47limit bsoft=5g bhard=6g %s47 /homen", $1' /etc/passwd
You could use the similar escape in hex, x27
, but it can get misinterpreted in some implementations if the following character is a valid hexadecimal digit. (And of course I assumed ASCII or an ASCII-compatible character set, e.g. UTF-8.)
for f in /etc/passwd;
This is a bit silly as there's really no loop with just one value.
But the issue seems to be printing single quotes from awk. You could escape them in the shell, but you could also use backslash-escapes within awk to print them. OOO
is the character with numerical value OOO (in octal), so 47
is '
. So this would be one way to do it:
awk -F: -vID=$ID_minimum '$3>=1000 && $1!="nfsnobody"
printf "xfs_quota -x -c 47limit bsoft=5g bhard=6g %s47 /homen", $1' /etc/passwd
You could use the similar escape in hex, x27
, but it can get misinterpreted in some implementations if the following character is a valid hexadecimal digit. (And of course I assumed ASCII or an ASCII-compatible character set, e.g. UTF-8.)
edited 8 hours ago
answered 8 hours ago
ilkkachuilkkachu
68.6k10 gold badges113 silver badges198 bronze badges
68.6k10 gold badges113 silver badges198 bronze badges
Note that it's fine here asl
is not a hex digit, but"x27dfn"
would be treated as"x27" "df"
in busybox awk or mawk but as"xdf"
(0x27df
cast to 8 bit char) in the original awk and gawk (that's the reason why POSIX doesn't specifyxHH
). Octals (47
) don't that the same problem and are POSIX. In any case, that assumes an ASCII system (a reasonable assumption these days).
– Stéphane Chazelas
8 hours ago
add a comment
|
Note that it's fine here asl
is not a hex digit, but"x27dfn"
would be treated as"x27" "df"
in busybox awk or mawk but as"xdf"
(0x27df
cast to 8 bit char) in the original awk and gawk (that's the reason why POSIX doesn't specifyxHH
). Octals (47
) don't that the same problem and are POSIX. In any case, that assumes an ASCII system (a reasonable assumption these days).
– Stéphane Chazelas
8 hours ago
Note that it's fine here as
l
is not a hex digit, but "x27dfn"
would be treated as "x27" "df"
in busybox awk or mawk but as "xdf"
(0x27df
cast to 8 bit char) in the original awk and gawk (that's the reason why POSIX doesn't specify xHH
). Octals (47
) don't that the same problem and are POSIX. In any case, that assumes an ASCII system (a reasonable assumption these days).– Stéphane Chazelas
8 hours ago
Note that it's fine here as
l
is not a hex digit, but "x27dfn"
would be treated as "x27" "df"
in busybox awk or mawk but as "xdf"
(0x27df
cast to 8 bit char) in the original awk and gawk (that's the reason why POSIX doesn't specify xHH
). Octals (47
) don't that the same problem and are POSIX. In any case, that assumes an ASCII system (a reasonable assumption these days).– Stéphane Chazelas
8 hours ago
add a comment
|
Use the -f -
option to awk to take the script from stdin and a here-document:
awk -F: -v "ID=$ID_minimum" -f - <<'EOT' /etc/passwd
$3>=1000 && $1!="nfsnobody"
print "xfs_quota -x -c 'limit bsoft=5g bhard=6g "$1"' /home "
EOT
add a comment
|
Use the -f -
option to awk to take the script from stdin and a here-document:
awk -F: -v "ID=$ID_minimum" -f - <<'EOT' /etc/passwd
$3>=1000 && $1!="nfsnobody"
print "xfs_quota -x -c 'limit bsoft=5g bhard=6g "$1"' /home "
EOT
add a comment
|
Use the -f -
option to awk to take the script from stdin and a here-document:
awk -F: -v "ID=$ID_minimum" -f - <<'EOT' /etc/passwd
$3>=1000 && $1!="nfsnobody"
print "xfs_quota -x -c 'limit bsoft=5g bhard=6g "$1"' /home "
EOT
Use the -f -
option to awk to take the script from stdin and a here-document:
awk -F: -v "ID=$ID_minimum" -f - <<'EOT' /etc/passwd
$3>=1000 && $1!="nfsnobody"
print "xfs_quota -x -c 'limit bsoft=5g bhard=6g "$1"' /home "
EOT
answered 6 hours ago
mosvymosvy
17.3k2 gold badges23 silver badges54 bronze badges
17.3k2 gold badges23 silver badges54 bronze badges
add a comment
|
add a comment
|
This did it.
awk -F: -vID=$ID_minimum '$3>=1000 && $1!="nfsnobody" print "xfs_quota -x -c '"'"'limit bsoft=5g bhard=6g ''"$1"'''"'"' /home "' /etc/passwd
New contributor
Yo dawg I heard you like quotes...
– Jesse_b
9 hours ago
@Jesse_b, yes, you can't put single quotes inside a single-quoted string, so you have to end it first, and then quote the single quote you want to insert. It doesn't matter if you do'''
or'"'"'
. Both work, both look annoying.
– ilkkachu
9 hours ago
1
@ilkkachu: It was a joke in the theme of the xzibit meme.
– Jesse_b
9 hours ago
@OP, hopefully you saw jordanm's comment about your loop being unnecessary. Your loop is only ever run once so it's not different than simply running the same awk command outside of a loop.
– Jesse_b
9 hours ago
add a comment
|
This did it.
awk -F: -vID=$ID_minimum '$3>=1000 && $1!="nfsnobody" print "xfs_quota -x -c '"'"'limit bsoft=5g bhard=6g ''"$1"'''"'"' /home "' /etc/passwd
New contributor
Yo dawg I heard you like quotes...
– Jesse_b
9 hours ago
@Jesse_b, yes, you can't put single quotes inside a single-quoted string, so you have to end it first, and then quote the single quote you want to insert. It doesn't matter if you do'''
or'"'"'
. Both work, both look annoying.
– ilkkachu
9 hours ago
1
@ilkkachu: It was a joke in the theme of the xzibit meme.
– Jesse_b
9 hours ago
@OP, hopefully you saw jordanm's comment about your loop being unnecessary. Your loop is only ever run once so it's not different than simply running the same awk command outside of a loop.
– Jesse_b
9 hours ago
add a comment
|
This did it.
awk -F: -vID=$ID_minimum '$3>=1000 && $1!="nfsnobody" print "xfs_quota -x -c '"'"'limit bsoft=5g bhard=6g ''"$1"'''"'"' /home "' /etc/passwd
New contributor
This did it.
awk -F: -vID=$ID_minimum '$3>=1000 && $1!="nfsnobody" print "xfs_quota -x -c '"'"'limit bsoft=5g bhard=6g ''"$1"'''"'"' /home "' /etc/passwd
New contributor
edited 5 hours ago
mosvy
17.3k2 gold badges23 silver badges54 bronze badges
17.3k2 gold badges23 silver badges54 bronze badges
New contributor
answered 9 hours ago
ZCTZCT
162 bronze badges
162 bronze badges
New contributor
New contributor
Yo dawg I heard you like quotes...
– Jesse_b
9 hours ago
@Jesse_b, yes, you can't put single quotes inside a single-quoted string, so you have to end it first, and then quote the single quote you want to insert. It doesn't matter if you do'''
or'"'"'
. Both work, both look annoying.
– ilkkachu
9 hours ago
1
@ilkkachu: It was a joke in the theme of the xzibit meme.
– Jesse_b
9 hours ago
@OP, hopefully you saw jordanm's comment about your loop being unnecessary. Your loop is only ever run once so it's not different than simply running the same awk command outside of a loop.
– Jesse_b
9 hours ago
add a comment
|
Yo dawg I heard you like quotes...
– Jesse_b
9 hours ago
@Jesse_b, yes, you can't put single quotes inside a single-quoted string, so you have to end it first, and then quote the single quote you want to insert. It doesn't matter if you do'''
or'"'"'
. Both work, both look annoying.
– ilkkachu
9 hours ago
1
@ilkkachu: It was a joke in the theme of the xzibit meme.
– Jesse_b
9 hours ago
@OP, hopefully you saw jordanm's comment about your loop being unnecessary. Your loop is only ever run once so it's not different than simply running the same awk command outside of a loop.
– Jesse_b
9 hours ago
Yo dawg I heard you like quotes...
– Jesse_b
9 hours ago
Yo dawg I heard you like quotes...
– Jesse_b
9 hours ago
@Jesse_b, yes, you can't put single quotes inside a single-quoted string, so you have to end it first, and then quote the single quote you want to insert. It doesn't matter if you do
'''
or '"'"'
. Both work, both look annoying.– ilkkachu
9 hours ago
@Jesse_b, yes, you can't put single quotes inside a single-quoted string, so you have to end it first, and then quote the single quote you want to insert. It doesn't matter if you do
'''
or '"'"'
. Both work, both look annoying.– ilkkachu
9 hours ago
1
1
@ilkkachu: It was a joke in the theme of the xzibit meme.
– Jesse_b
9 hours ago
@ilkkachu: It was a joke in the theme of the xzibit meme.
– Jesse_b
9 hours ago
@OP, hopefully you saw jordanm's comment about your loop being unnecessary. Your loop is only ever run once so it's not different than simply running the same awk command outside of a loop.
– Jesse_b
9 hours ago
@OP, hopefully you saw jordanm's comment about your loop being unnecessary. Your loop is only ever run once so it's not different than simply running the same awk command outside of a loop.
– Jesse_b
9 hours ago
add a comment
|
ZCT is a new contributor. Be nice, and check out our Code of Conduct.
ZCT is a new contributor. Be nice, and check out our Code of Conduct.
ZCT is a new contributor. Be nice, and check out our Code of Conduct.
ZCT is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f541632%2fbash-awk-command-with-quotes%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Possible duplicate of How to escape quotes in shell?
– jordanm
9 hours ago
2
Your loop only ever iterates once.
– jordanm
9 hours ago
@jordanm I don't think that applies to
awk
– Jesse_b
9 hours ago
2
@Jesse_b his quoting issue is shell quoting, doesn't really have anything to do with awk. He needs to escape nested single quotes.
– jordanm
9 hours ago
1
Related: How to escape a single quote inside awk
– Freddy
9 hours ago