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;








1















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...










share|improve this question









New contributor



ZCT is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 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


















1















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...










share|improve this question









New contributor



ZCT is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 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














1












1








1








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...










share|improve this question









New contributor



ZCT is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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






share|improve this question









New contributor



ZCT is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.










share|improve this question









New contributor



ZCT is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








share|improve this question




share|improve this question








edited 9 hours ago









Jesse_b

18.8k3 gold badges46 silver badges88 bronze badges




18.8k3 gold badges46 silver badges88 bronze badges






New contributor



ZCT is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








asked 9 hours ago









ZCTZCT

162 bronze badges




162 bronze badges




New contributor



ZCT is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




New contributor




ZCT is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • 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













  • 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








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











4 Answers
4






active

oldest

votes


















5
















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.






share|improve this answer



























  • the only answer to correctly use getent rather than parse /etc/passwd.

    – cas
    4 hours ago


















2
















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.)






share|improve this answer



























  • 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


















1
















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





share|improve this answer
































    1
















    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





    share|improve this answer










    New contributor



    ZCT is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















    • 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













    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.









    draft saved

    draft discarded
















    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









    5
















    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.






    share|improve this answer



























    • the only answer to correctly use getent rather than parse /etc/passwd.

      – cas
      4 hours ago















    5
















    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.






    share|improve this answer



























    • the only answer to correctly use getent rather than parse /etc/passwd.

      – cas
      4 hours ago













    5














    5










    5









    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.






    share|improve this answer















    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.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited 8 hours ago

























    answered 8 hours ago









    KusalanandaKusalananda

    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

















    • 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













    2
















    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.)






    share|improve this answer



























    • 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















    2
















    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.)






    share|improve this answer



























    • 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













    2














    2










    2









    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.)






    share|improve this answer















    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.)







    share|improve this answer














    share|improve this answer



    share|improve this answer








    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 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
















    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











    1
















    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





    share|improve this answer





























      1
















      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





      share|improve this answer



























        1














        1










        1









        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





        share|improve this answer













        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






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 6 hours ago









        mosvymosvy

        17.3k2 gold badges23 silver badges54 bronze badges




        17.3k2 gold badges23 silver badges54 bronze badges
























            1
















            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





            share|improve this answer










            New contributor



            ZCT is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.





















            • 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















            1
















            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





            share|improve this answer










            New contributor



            ZCT is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.





















            • 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













            1














            1










            1









            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





            share|improve this answer










            New contributor



            ZCT is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.









            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






            share|improve this answer










            New contributor



            ZCT is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.








            share|improve this answer



            share|improve this answer








            edited 5 hours ago









            mosvy

            17.3k2 gold badges23 silver badges54 bronze badges




            17.3k2 gold badges23 silver badges54 bronze badges






            New contributor



            ZCT is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.








            answered 9 hours ago









            ZCTZCT

            162 bronze badges




            162 bronze badges




            New contributor



            ZCT is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.




            New contributor




            ZCT is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.

















            • 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











            • @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











            ZCT is a new contributor. Be nice, and check out our Code of Conduct.









            draft saved

            draft discarded

















            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

            Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

            Ласкавець круглолистий Зміст Опис | Поширення | Галерея | Примітки | Посилання | Навігаційне меню58171138361-22960890446Bupleurum rotundifoliumEuro+Med PlantbasePlants of the World Online — Kew ScienceGermplasm Resources Information Network (GRIN)Ласкавецькн. VI : Літери Ком — Левиправивши або дописавши її