bash

Why do bash command line arguments after 9 require curly brackets?

回眸只為那壹抹淺笑 提交于 2021-02-07 11:57:15
问题 This may not be the most thought provoking question, but nevertheless has struck my curiosity. I have not been able to come across any answer (let alone a definitive one) on the web. While reading Advanced Shell Scripting, I came across this section regarding command line positional arguments which states that anything after the the ninth argument must be surrounded by ${} (the longer form of variable referencing/substitution). Simply put, why must you reference command line argument ten (and

What is the difference between “else if” and “elif” in bash?

ぐ巨炮叔叔 提交于 2021-02-07 11:13:57
问题 I've got the following shell script that's supposed to simply stage a few Java .ear/.war files to JBoss: SUCCESS=false DEPLOY_PATH=/apps/jboss/server/default/deploy E_NOARGS=75 M_USAGE="usage: $0 {rcm|hcm}" M_MISSING_RCM="missing: rcm.war file not present" M_MISSING_HCM="missing: hcm.ear or hcm.war file not present" if [ -z "$1" ] then echo $M_USAGE exit $E_NOARGS else M_START="deploying $1 ..." M_FINISH="finished deploying $1" fi until [ -z "$1" ] do echo $M_START case "$1" in rcm*) # do a

Nested bash autocompletion script

懵懂的女人 提交于 2021-02-07 10:36:03
问题 I've been trying to add bash completion support to a command line program I've been using lately, but it seems that I've hit a wall. Here are the commands and subcommands I'd like to auto-complete Main command is foo , autocompletion should be performed for the subcommands version , process , and help . Further autcompletion depends on the subcommand. If the user enters - after the main command, autocompletion performs completion for these word: --activate or --deactivate If the user enters -

Nested bash autocompletion script

我与影子孤独终老i 提交于 2021-02-07 10:35:25
问题 I've been trying to add bash completion support to a command line program I've been using lately, but it seems that I've hit a wall. Here are the commands and subcommands I'd like to auto-complete Main command is foo , autocompletion should be performed for the subcommands version , process , and help . Further autcompletion depends on the subcommand. If the user enters - after the main command, autocompletion performs completion for these word: --activate or --deactivate If the user enters -

How to get just a list of yum updates

こ雲淡風輕ζ 提交于 2021-02-07 10:33:17
问题 OK I have always had this problem. I want JUST the available updates listed in a file via bash script from a Linux system (RHEL or Fedora) using yum but I always have to deal with the Header information created which looks like this: Loaded plugins: XXXX-repo XXXX-updates : WWWWWW-repo something-updates QQQQQ-updates Updated packages package1.i686 1:234 RHEL 6.5 updates package2.i686 1:234 RHEL 6.5 updates package3.i686 1-234 RHEL 6.5 updates package4.noarch 1.234 RHEL 6.5 updates All I want

How to assign the output of a background job into a bash variable?

这一生的挚爱 提交于 2021-02-07 09:51:47
问题 I would like to run a background job in bash and assign its result to a variable. I prefer not to use temporary files and I would love to run multiple similar background tasks at the same time. root@root:/# var=$(echo "hello world") root@root:/# echo $var hello world root@root:/# back_var=$(sleep 2s && echo "hello world back") & [1] 2102 root@root:/# wait root@root:/#jobs [1]+ Done back_var=$(sleep 2s && echo "hello world back") root@root:/# echo $back_var root@root:/# I prefer not to use gnu

Print all lines between two patterns, exclusive, first instance only (in sed, AWK or Perl) [duplicate]

白昼怎懂夜的黑 提交于 2021-02-07 09:33:34
问题 This question already has answers here : How to print lines between two patterns, inclusive or exclusive (in sed, AWK or Perl)? (9 answers) Closed 1 year ago . Using sed, AWK (or Perl), how do you print all lines between (the first instance of) two patterns, exclusive of the patterns? 1 That is, given as input: aaa PATTERN1 bbb ccc ddd PATTERN2 eee Or possibly even: aaa PATTERN1 bbb ccc ddd PATTERN2 eee fff PATTERN1 ggg hhh iii PATTERN2 jjj I would expect, in both cases: bbb ccc ddd 1 A

Why does running npm test result in: '.' is not recognized as an internal or external command, operable program or batch file.?

泪湿孤枕 提交于 2021-02-07 09:20:21
问题 I have the following installed: Windows 10 Git bash (mingw64) Node.js v8.7.0 npm version 5.4.2 Packages: chai 4.4.1 mocha 3.5.0 I have a sample mocha test that will always pass when it actually runs. The command I'm running in my shell: npm test Output: ./node_modules/mocha/bin/_mocha '.' is not recognized as an internal or external command, operable program or batch file. npm ERR! Test failed. See above for more details. For some reason I'm able to run this command directly: ./node_modules

Why does running npm test result in: '.' is not recognized as an internal or external command, operable program or batch file.?

ぐ巨炮叔叔 提交于 2021-02-07 09:17:56
问题 I have the following installed: Windows 10 Git bash (mingw64) Node.js v8.7.0 npm version 5.4.2 Packages: chai 4.4.1 mocha 3.5.0 I have a sample mocha test that will always pass when it actually runs. The command I'm running in my shell: npm test Output: ./node_modules/mocha/bin/_mocha '.' is not recognized as an internal or external command, operable program or batch file. npm ERR! Test failed. See above for more details. For some reason I'm able to run this command directly: ./node_modules

awk sort multidimensional array [duplicate]

放肆的年华 提交于 2021-02-07 08:54:33
问题 This question already has an answer here : Appending an element to associative array awk (1 answer) Closed 4 years ago . GNU awk supports multidimensional arrays: q[1][1] = "dog" q[1][2] = 999 q[2][1] = "mouse" q[2][2] = 777 q[3][1] = "bird" q[3][2] = 888 I would like to sort the "second column" of q such that I am left with: q[1][1] = "mouse" q[1][2] = 777 q[2][1] = "bird" q[2][2] = 888 q[3][1] = "dog" q[3][2] = 999 as you can see the "first column" values moved to keep with the second. I