![]() Sometimes even the config file path gets passed through the command-line argument.īeing a runtime, of course, Bun supports the command-line arguments supplied to the application. >node args.How to get command-line arguments in Bun?Įvery application needs to handle command-line arguments, unless all the options are read from a config file. Quoted option values in the Windows Command shell: >node args.mjs -str 'two words' -str "two words" >node args.mjs 'back slash\' '\t\n' '%USERNAME%' In the Windows Command shell single quotes are not special in any way: >node args.mjs "say \"hi\"" "\t\n" "%USERNAME%" args.mjs -str="two words" -str='two words' args.mjs -str "two words" -str 'two words' The following interaction demonstrates option values that are doube-quoted and single-quoted: %. Single quotes: all content is passed on verbatim and we can’t escape quotes: %. On Unix, these are the differences between double quotes and single quotes:ĭouble quotes: we can escape quotes with backslashes (which are otherwise passed on verbatim) and variables are interpolated: %. To examine how shells parse quoted values, we again use the script args.mjs: #!/usr/bin/env node console. The latter is not supported by all shells, however. If we want to use values that contain spaces, we need to quote them – with double quotes or single quotes. So far, all option values and positional values were single words. Written as a JavaScript function call, the previous example would look like this (in JavaScript, options usually come last): argsMjs( 'home.html', 'main.js', ),
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |