Prevent awk from removing “” (backslashes) in variableWhy *not* parse `ls` (and what to do instead)?When is double-quoting necessary?awk: forcing a return status?awk with if statementsExternal commands in AWKHow can I call a bash function in bash script inside awk?Trouble pasting specific fields using awkAWK csv manipulationHow to prevent parameter expansion around a variable I want to be resolved?How to use AWK select the file name in URL?

How can I justify this without determining the determinant?

Sorting sequences independent of color

Unstable manifolds of a Morse function give a CW complex

Draw the Ionising Radiation Hazard Symbol

Why is a living creature being frozen in carbonite in “The Mandalorian” so common when it seemed so risky in “The Empire Strikes Back?”

My Programming Manager constantly asks for updates and is never satisfied with my performance. How do I approach this?

BGP and NAT Not working

Why do investors pay trillions for minority stakes in companies, when their only potential payback is modest uncertain dividends?

Why the translation is not linear transformation?

What's the best way of typing the following 58 equations into LaTeX?

How to create electric light with 1300s technology

Why didn't Philippine Airlines Flight 113 dump fuel prior to forced landing?

Logic inside a 3 or 4 way light switch?

How can an AI train itself if no one is telling it if its answer is correct or wrong?

What do you call candidates in elections who don't actually have a chance to win and only create an illusion of competition?

Is an afterburner louder than the same jet engine without it?

How to help a male-presenting person shop for women's clothes?

What is the rationale for single engine military aircraft?

In the sentence "der hatte doch eine Brille", why do we use 'der' instead of 'er'?

Implementing solvers with Object Oriented Programming

What was the first operating system called DOS?

What is a recently obsolete computer storage device that would be significantly difficult to extract data from?

Got stack in calculating state-space representation

Cheating On Lichess?



Prevent awk from removing “” (backslashes) in variable


Why *not* parse `ls` (and what to do instead)?When is double-quoting necessary?awk: forcing a return status?awk with if statementsExternal commands in AWKHow can I call a bash function in bash script inside awk?Trouble pasting specific fields using awkAWK csv manipulationHow to prevent parameter expansion around a variable I want to be resolved?How to use AWK select the file name in URL?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;









4


















I have this line of code for the shell:



ls -1 *.mp3| awk -v here="$(cygpath -w $PWD)" -v source="$source" 'print "File Name: "$0"n"here"n"source'


Unfortunately it outputs:



File Name: Data 00053.mp3
C:UsersathenaWorkProject_10.MBT
Source: Converted from RAW


This line C:UsersathenaWorkProject_10.MBT
Should be C:UsersathenaWorkProject_100.MBT



I am now lost, a lot to learn here.










share|improve this question






















  • 1





    See also cygpath -aw . for the current working directory in Windows format.

    – Stéphane Chazelas
    Sep 19 at 9:28

















4


















I have this line of code for the shell:



ls -1 *.mp3| awk -v here="$(cygpath -w $PWD)" -v source="$source" 'print "File Name: "$0"n"here"n"source'


Unfortunately it outputs:



File Name: Data 00053.mp3
C:UsersathenaWorkProject_10.MBT
Source: Converted from RAW


This line C:UsersathenaWorkProject_10.MBT
Should be C:UsersathenaWorkProject_100.MBT



I am now lost, a lot to learn here.










share|improve this question






















  • 1





    See also cygpath -aw . for the current working directory in Windows format.

    – Stéphane Chazelas
    Sep 19 at 9:28













4













4









4


1






I have this line of code for the shell:



ls -1 *.mp3| awk -v here="$(cygpath -w $PWD)" -v source="$source" 'print "File Name: "$0"n"here"n"source'


Unfortunately it outputs:



File Name: Data 00053.mp3
C:UsersathenaWorkProject_10.MBT
Source: Converted from RAW


This line C:UsersathenaWorkProject_10.MBT
Should be C:UsersathenaWorkProject_100.MBT



I am now lost, a lot to learn here.










share|improve this question
















I have this line of code for the shell:



ls -1 *.mp3| awk -v here="$(cygpath -w $PWD)" -v source="$source" 'print "File Name: "$0"n"here"n"source'


Unfortunately it outputs:



File Name: Data 00053.mp3
C:UsersathenaWorkProject_10.MBT
Source: Converted from RAW


This line C:UsersathenaWorkProject_10.MBT
Should be C:UsersathenaWorkProject_100.MBT



I am now lost, a lot to learn here.







bash awk quoting variable






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 19 at 14:33









Jeff Schaller

52.3k11 gold badges76 silver badges172 bronze badges




52.3k11 gold badges76 silver badges172 bronze badges










asked Sep 19 at 6:20









Ken IngramKen Ingram

2051 silver badge6 bronze badges




2051 silver badge6 bronze badges










  • 1





    See also cygpath -aw . for the current working directory in Windows format.

    – Stéphane Chazelas
    Sep 19 at 9:28












  • 1





    See also cygpath -aw . for the current working directory in Windows format.

    – Stéphane Chazelas
    Sep 19 at 9:28







1




1





See also cygpath -aw . for the current working directory in Windows format.

– Stéphane Chazelas
Sep 19 at 9:28





See also cygpath -aw . for the current working directory in Windows format.

– Stéphane Chazelas
Sep 19 at 9:28










1 Answer
1






active

oldest

votes


















8



















That's an issue relating to how awk treats the value passed using -v. It interprets the backslashes in the passed string.



Instead, pass it through an environment variable:



here="$(cygpath -w "$PWD")" awk ... ' print ... ENVIRON["here"] ... '


ENVIRON is an associative array in awk that contains the values of the variables in the current environment, keyed by name.



Also related to your code:



  • Why *not* parse `ls` (and what to do instead)?

  • When is double-quoting necessary?





share|improve this answer



























  • It solved the issue for sure.

    – Ken Ingram
    Sep 19 at 21:43











  • It doesn't work for multiple variables though. Any thoughts?

    – Ken Ingram
    Sep 20 at 1:04






  • 1





    @KenIngram Did you try? a=1 b=2 c=3 awk 'BEGIN print ENVIRON["a"], ENVIRON["b"], ENVIRON["c"] '. You could obviously just export the variables instead of assigning them on the same command line as awk (but that would make them part of your script's environment too).

    – Kusalananda
    Sep 20 at 5:27













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



);














draft saved

draft discarded
















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f542560%2fprevent-awk-from-removing-backslashes-in-variable%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown


























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









8



















That's an issue relating to how awk treats the value passed using -v. It interprets the backslashes in the passed string.



Instead, pass it through an environment variable:



here="$(cygpath -w "$PWD")" awk ... ' print ... ENVIRON["here"] ... '


ENVIRON is an associative array in awk that contains the values of the variables in the current environment, keyed by name.



Also related to your code:



  • Why *not* parse `ls` (and what to do instead)?

  • When is double-quoting necessary?





share|improve this answer



























  • It solved the issue for sure.

    – Ken Ingram
    Sep 19 at 21:43











  • It doesn't work for multiple variables though. Any thoughts?

    – Ken Ingram
    Sep 20 at 1:04






  • 1





    @KenIngram Did you try? a=1 b=2 c=3 awk 'BEGIN print ENVIRON["a"], ENVIRON["b"], ENVIRON["c"] '. You could obviously just export the variables instead of assigning them on the same command line as awk (but that would make them part of your script's environment too).

    – Kusalananda
    Sep 20 at 5:27
















8



















That's an issue relating to how awk treats the value passed using -v. It interprets the backslashes in the passed string.



Instead, pass it through an environment variable:



here="$(cygpath -w "$PWD")" awk ... ' print ... ENVIRON["here"] ... '


ENVIRON is an associative array in awk that contains the values of the variables in the current environment, keyed by name.



Also related to your code:



  • Why *not* parse `ls` (and what to do instead)?

  • When is double-quoting necessary?





share|improve this answer



























  • It solved the issue for sure.

    – Ken Ingram
    Sep 19 at 21:43











  • It doesn't work for multiple variables though. Any thoughts?

    – Ken Ingram
    Sep 20 at 1:04






  • 1





    @KenIngram Did you try? a=1 b=2 c=3 awk 'BEGIN print ENVIRON["a"], ENVIRON["b"], ENVIRON["c"] '. You could obviously just export the variables instead of assigning them on the same command line as awk (but that would make them part of your script's environment too).

    – Kusalananda
    Sep 20 at 5:27














8















8











8









That's an issue relating to how awk treats the value passed using -v. It interprets the backslashes in the passed string.



Instead, pass it through an environment variable:



here="$(cygpath -w "$PWD")" awk ... ' print ... ENVIRON["here"] ... '


ENVIRON is an associative array in awk that contains the values of the variables in the current environment, keyed by name.



Also related to your code:



  • Why *not* parse `ls` (and what to do instead)?

  • When is double-quoting necessary?





share|improve this answer
















That's an issue relating to how awk treats the value passed using -v. It interprets the backslashes in the passed string.



Instead, pass it through an environment variable:



here="$(cygpath -w "$PWD")" awk ... ' print ... ENVIRON["here"] ... '


ENVIRON is an associative array in awk that contains the values of the variables in the current environment, keyed by name.



Also related to your code:



  • Why *not* parse `ls` (and what to do instead)?

  • When is double-quoting necessary?






share|improve this answer















share|improve this answer




share|improve this answer








edited Sep 19 at 9:24









Stéphane Chazelas

345k59 gold badges675 silver badges1056 bronze badges




345k59 gold badges675 silver badges1056 bronze badges










answered Sep 19 at 6:37









KusalanandaKusalananda

174k20 gold badges332 silver badges537 bronze badges




174k20 gold badges332 silver badges537 bronze badges















  • It solved the issue for sure.

    – Ken Ingram
    Sep 19 at 21:43











  • It doesn't work for multiple variables though. Any thoughts?

    – Ken Ingram
    Sep 20 at 1:04






  • 1





    @KenIngram Did you try? a=1 b=2 c=3 awk 'BEGIN print ENVIRON["a"], ENVIRON["b"], ENVIRON["c"] '. You could obviously just export the variables instead of assigning them on the same command line as awk (but that would make them part of your script's environment too).

    – Kusalananda
    Sep 20 at 5:27


















  • It solved the issue for sure.

    – Ken Ingram
    Sep 19 at 21:43











  • It doesn't work for multiple variables though. Any thoughts?

    – Ken Ingram
    Sep 20 at 1:04






  • 1





    @KenIngram Did you try? a=1 b=2 c=3 awk 'BEGIN print ENVIRON["a"], ENVIRON["b"], ENVIRON["c"] '. You could obviously just export the variables instead of assigning them on the same command line as awk (but that would make them part of your script's environment too).

    – Kusalananda
    Sep 20 at 5:27

















It solved the issue for sure.

– Ken Ingram
Sep 19 at 21:43





It solved the issue for sure.

– Ken Ingram
Sep 19 at 21:43













It doesn't work for multiple variables though. Any thoughts?

– Ken Ingram
Sep 20 at 1:04





It doesn't work for multiple variables though. Any thoughts?

– Ken Ingram
Sep 20 at 1:04




1




1





@KenIngram Did you try? a=1 b=2 c=3 awk 'BEGIN print ENVIRON["a"], ENVIRON["b"], ENVIRON["c"] '. You could obviously just export the variables instead of assigning them on the same command line as awk (but that would make them part of your script's environment too).

– Kusalananda
Sep 20 at 5:27






@KenIngram Did you try? a=1 b=2 c=3 awk 'BEGIN print ENVIRON["a"], ENVIRON["b"], ENVIRON["c"] '. You could obviously just export the variables instead of assigning them on the same command line as awk (but that would make them part of your script's environment too).

– Kusalananda
Sep 20 at 5:27



















draft saved

draft discarded















































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%2f542560%2fprevent-awk-from-removing-backslashes-in-variable%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

Tamil (spriik) Luke uk diar | Nawigatjuun

Align equal signs while including text over equalitiesAMS align: left aligned text/math plus multicolumn alignmentMultiple alignmentsAligning equations in multiple placesNumbering and aligning an equation with multiple columnsHow to align one equation with another multline equationUsing \ in environments inside the begintabularxNumber equations and preserving alignment of equal signsHow can I align equations to the left and to the right?Double equation alignment problem within align enviromentAligned within align: Why are they right-aligned?

Where does the image of a data connector as a sharp metal spike originate from?Where does the concept of infected people turning into zombies only after death originate from?Where does the motif of a reanimated human head originate?Where did the notion that Dragons could speak originate?Where does the archetypal image of the 'Grey' alien come from?Where did the suffix '-Man' originate?Where does the notion of being injured or killed by an illusion originate?Where did the term “sophont” originate?Where does the trope of magic spells being driven by advanced technology originate from?Where did the term “the living impaired” originate?