Questions tagged [bash4]

is a Unix shell written by Brian Fox for the GNU Project as a free software replacement for the Bourne shell (sh). Version 4 was released on 20th of February, 2009.

Bash is a command processor, typically run in a text window, allowing the user to type commands which cause actions. Bash can also read commands from a file, called a script. Like all Unix shells, it supports filename wildcarding, piping, here documents, command substitution, variables and control structures for condition-testing and iteration. The keywords, syntax and other basic features of the language were all copied from sh. Other features, e.g., history, were copied from csh and ksh. Bash is a POSIX shell but with a number of extensions.

The name itself is an acronym, a pun, and a description. As an acronym, it stands for Bourne-again shell, referring to its objective as a free replacement for the Bourne shell. As a pun, it expresses that objective in a phrase that sounds similar to born again, a term for spiritual rebirth. The name is also descriptive of what it did, bashing together the features of sh, csh and ksh.

Source: Wikipedia [Bash (Unix Shell)]

79 questions
5
votes
3 answers

How can i log error from my script.sh every time I run the script.sh and save output to a file?

How can I save the error output when running my script to a file? I have my code bellow, but the code does not track error and save the error to test.log14. Can somebody give me a hint on what could be wrong in my code... …
Bruno Alves
  • 51
  • 1
  • 1
  • 7
5
votes
3 answers

bash: iterating through txt file lines can't read last line

while read p; do echo $p done < file.txt this code can read all lines in the file.txt except the last line any ideas why. Thanks
Hady Hallak
  • 347
  • 4
  • 8
4
votes
1 answer

How can I update an associative array inside a function passing it by parameter?

I have the following code which reads all the fields of a Json file (the path being PRIVATE_REGISTRATION_FILE and stores them into an associative array (PRIVATE_FIELDS) which I query later in my code: declare -A PRIVATE_FIELDS for PRICING_FIELD in…
Matteo NNZ
  • 11,930
  • 12
  • 52
  • 89
4
votes
1 answer

Bash 4.4 vi-mode coloring

since bash 4.4 you can set variables vi-ins-mode-string and vi-cmd-string in .inputrc. I've been trying to change the foreground and background color of each of those strings by using tput setab number and tput setaf number, no success. I guess it…
xxxxx
  • 159
  • 9
4
votes
1 answer

Cannot evaluate script arguments from function

I've started writing shell scripts again and I've found myself in a situation where I frequently have to write debug echo's to trace what the script is doing. The, easy, way I used to do this right was to write something like this…
gxtaillon
  • 1,016
  • 1
  • 19
  • 33
4
votes
5 answers

Multiple matches in a string using regex in bash

Been looking for some more advanced regex info on regex with bash and have not found much information on it. Here's the concept, with a simple string: myString="DO-BATCH BATCH-DO" if [[ $myString =~ ([[:alpha:]]*)-([[:alpha:]]*) ]]; then echo…
pn1 dude
  • 4,286
  • 5
  • 30
  • 26
3
votes
1 answer

Is it possible in Bash 4.0 to substring and uppercase a variable in one

Given a variable var=toucan I can do the following: echo ${var^^} TOUCAN echo ${var:3} can Is it possible to do something similar to echo ${var:3^^} to get CAN? echo ${var:3^^} bash: var: 3^^: syntax error: operand expected (error token is "^")
Matt Simons
  • 384
  • 3
  • 8
3
votes
2 answers

Work-around for $@ unbound variable in Bash 4.0.0?

In specifically Bash version 4.0.0, is there any way to work around the use of an empty $@ raising an unbound variable error when set -u is enabled? Consider the following: #!/usr/bin/env bash-4.0.0-1 set -xvu echo "$BASH_VERSION" echo…
3
votes
1 answer

Regular Expression : bash 3 vs bash 4

The follow code with a regular expression check does not outputs the same result between bash 3 and bash 4: TESTCASE="testcase0" [[ ${TESTCASE} =~ "^testcase[0-9\.]*$" ]] echo $? echo ${BASH_REMATCH} bash 3.2 outputs a successful regular…
LAL
  • 480
  • 5
  • 13
2
votes
2 answers

How do i cut section with start and end using Bash?

When i am doing pactl list i get lot of information. Out of those information, i am trying to only get the part start with Sink #0 till end of that section. 1) Information's Sink #0 State: SUSPENDED Name: auto_null Description: Dummy…
user285594
2
votes
1 answer

Unable to use Checkjobs and Autocd in Bash 4

There are new options in Bash 4: checkjobs and autocd. However, I did not find documentation for them at man bash I run unsuccessfully {checkjobs,autocd} I found the following in release notes There is a new `checkjobs` option that causes the…
Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697
2
votes
1 answer

Bash 4.2 Associative arrays throws "bad array subscript" error

I'm trying to create this associative array, but it throws an error because of the volumeClaimTemplates[0] This is my code: declare -A example=(["'spec.statefulSet.spec.volumeClaimTemplates[0].spec'"]="TEST") This is the…
2
votes
2 answers

Mac: Virtual Shell Bash Version does not Match Installed Version

I am trying to create shell scripts that make use of Bash 4.0's features. I am on a Mac using zshell as my main shell, and I have bash 4.0 installed via Homebrew. When I run bash --version from iTerm, I get: GNU bash, version 4.4.23(1)-release…
Glen Cooney
  • 51
  • 1
  • 6
2
votes
2 answers

Inconsistent behavior when replacing substring with tilde "~" in a BASH parameter expansion

I came across some strangely inconsistent behavior in BASH parameter expansions across a few different servers, while trying to write a quick function. On some versions of BASH, to use a tilde in a substring replacement, the tilde must be escaped,…
Luke Davis
  • 2,548
  • 2
  • 21
  • 43
2
votes
2 answers

Getting length of part of associative array (double) in Bash

I have an associative array that acts like it's usual double array. Structure is similar to this: [ [0,1], [0,1,2] ]. Code: declare -A array array[0,0]=0 array[0,1]=1 array[1,0]=0 array[1,1]=1 array[1,2]=2 How do I get lengths of array[0] and…
MOPO3OB
  • 383
  • 3
  • 16