Variable as bash array index?
Bash seems perfectly happy with variables as array indexes: $ array=(a b c) $ arrayindex=2 $ echo ${array[$arrayindex]} c $ array[$arrayindex]=MONKEY $ echo ${array[$arrayindex]} MONKEY
Bash seems perfectly happy with variables as array indexes: $ array=(a b c) $ arrayindex=2 $ echo ${array[$arrayindex]} c $ array[$arrayindex]=MONKEY $ echo ${array[$arrayindex]} MONKEY
A couple of syntactic issues. The variable definitions in Bash do not take spaces. It should have been MAXSIZE=500000, without spaces. The way comparison operation is done is incorrect. Instead of if [ (( $FILESIZE > MAXSIZE)) ];, you could very well use Bash’s own arithmetic operator alone and skip the [ operator to just … Read more
Git on Windows almost always uses a bash shell. So, it’s not Git setting the prompt as much as Bash does. There are two ways to set prompts in Bash. One is the PS1 command which is fairly flexible, but is limited to a particular set of escape character sequences. Unfortunately, Git information isn’t one … Read more
The :: is just a Naming Convention for function names. Is a coding-style such as snake_case or CamelCase The convention for Function names in shell style commonly is: Lower-case, with underscores to separate words. Separate libraries with ::. Parentheses are required after the function name. The keyword function is optional, but must be used consistently … Read more
I ran into the same problem. Here’s the workaround I’m using: Register the completion function with -o default, e.g., complete -o default -F _my_completion. When you want to complete a filename, just set COMPREPLY=() and let Readline take over (that’s what the -o default does). There’s a potential problem with this — you might be … Read more
Did you try with: for i in “one” “two”; do echo “$i”; done
Try a character class instead echo “$STRING” | egrep ‘[*]’
It works if ‘ is replaced with ” into this command on the script – STAMP=`date –date=”$1 day ago” +%y%m%d` The clue was the two different character ` and ‘ used in the error response – date: invalid date `$1 day ago’ An expert in bash scripting (not me) can probably explain why this has … Read more
The -n argument to test (aka [) means “is not empty”. The example you posted means “if $1 is not not empty. It’s a roundabout way of saying [ -z “$1” ]; ($1 is empty). You can learn more with help test. $1 and others ($2, $3..) are positional parameters. They’re what was passed as … Read more
With that line of code value=($(jq -r ‘.key1’ jsonFile)) you are assigning both values to an array. Note the outer parantheses () around the command. Thus you can access the values individually or echo the content of the entire array. $ echo “${value[@]}” aaaa bbbb $ echo “${value[0]}” aaaa $ echo “${value[1]}” bbbb Since you … Read more