JSON for command-line arguments -
It is believed that I want to write a tool which needs to accept some structured data, this command-line argument , And at that time, the environment?
For example
fudge_files "['file1', 'file2']" # The list of files can be used here fudge_files --dirs "['dir1' ',' Dir2 '] "pattern. * Or another .foo or in a more complicated example
fudge_files - -dst "{'txt': ['/ foo', '/ Bar '],' pdf ': [' / foo ']} "pattern. * Is this good or bad idea?
What are the disadvantages?
Most (all) shells
Once you have a valid "\" character in your data, it actually gets ugly. "You can come with hacks, but it will be painful and you can spend lot while trying to debug issues related to such quotes. And If you continue, and do this work, then, after 2-3 months, you might think that "I can put some of these in variables and eval to expand the variable in the string "or other insanity. Now you can debug the issue In addition to this, I've done a quick test using open ANSI strings that it will help, but $ var = $ " "$ Echo $ var" [file1, file2] "$ echo" $ var "" [File 1, file2] "$ var = $" "['file1', 'file2] [' file1 ',' file2 ' ] "MyANSIString with" $ var input " or $" is the definition of "ani string strings" like $ is "My Static ANSI String" Code> Note that in the first example, the shell first matches single quotes on the spot. , And stripped them of your input string. Hopefully this was the echo which was separating them, I used the best practice in the quote on the second echo line "$ var" Not used, single-quotes have gone: - ( I do not have much experience working with ANSI strings, so one can provide another solution which will maintain single and DBL quotes
Otherwise, I am not seeing this work.
Your job Wow is not quite clear, but is estimating that this is ending some of these values (I hope you do not have to type them), I think that if you're printing them on a separate program terminal , Then redirect to a file
json_emitting_program --args .... & gt; $ tmpFile or to eliminate tmp files Use the Unix tool designed, pipe | , and your device's STD-in Write to read data, it is command-line arguments. Then you say
json_emitting_program --args .... | Fudge_files Or, using a Tmp file
fudge_files & lt; "$ TmpFile" If the source of your data is in the AS MS Windows Output (for example), then you need Unix here-document , something like this cat - & gt; Make the file temporary on the file using. $ TmpFile & lt; & Lt; Paste your input, EOS, here and here and here. EOS Note that EOS should be on one line, there is no backward white space.
Shell should
Confirm that the file is there and is up-to-date
ls -l $ tmpFile and above, run your program
fudge_files & lt; "$ TmpFile" If you do not know, then you create a tmpFile with a simple assignment for any path / file name:
TmpFile = / path / to / myTempFile IHTH
Comments
Post a Comment