lnstools

Linux namespace tools
git clone https://ccx.te2000.cz/git/lnstools
Log | Files | Refs | README

args_to_sh.awk (377B)


      1 #!/bin/awk -f
      2 function die(msg) {
      3 	print msg >>"/dev/stderr"
      4 	exit 1
      5 }
      6 
      7 function s(re, t, str) {
      8 	gsub(re, t, str)
      9 	return str
     10 }
     11 
     12 function shquote(text) {
     13 	if(text !~ "[^-+,_./:@0-9A-Za-z]") {
     14 		return text
     15 	}
     16 	return "'" s("'", "'\\''", text) "'"
     17 }
     18 
     19 BEGIN {
     20 	printf "%s\n%s", "#!/bin/sh", "exec \"$@\""
     21 	for(i=1; i<ARGC; i++) {
     22 		printf " %s", shquote(ARGV[i])
     23 	}
     24 	ARGC = 1
     25 }