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
438
votes
5 answers

How to iterate over associative arrays in Bash

Based on an associative array in a Bash script, I need to iterate over it to get the key and value. #!/bin/bash declare -A array array[foo]=bar array[bar]=foo I actually don't understand how to get the key while using a for-in loop.
pex
  • 7,351
  • 4
  • 32
  • 41
313
votes
9 answers

How to write multiple line string using Bash with variables?

How can I write multi-lines in a file called myconfig.conf using BASH? #!/bin/bash kernel="2.6.39"; distro="xyz"; echo <<< EOL line 1, ${kernel} line 2, line 3, ${distro} line 4 line ... EOL >> /etc/myconfig.conf; cat /etc/myconfig.conf;
user285594
39
votes
4 answers

What method should I use to write error messages to 'stderr' using 'printf' in a bash script?

I want to direct the output of a printf in a bash script to stderr instead of stdout. I am not asking about redirecting either stderr or stdout from where ever they are currently routed. I just want to be able to send the output from a printf to…
irrational John
  • 580
  • 1
  • 6
  • 14
23
votes
6 answers

How to run BASH script in my Android?

My same BASH script is working in Fedora/CentOS. But I am testing one Android eee pad transformer. Where i have terminal access and i wrote a small test script. But its not working, how can i fix it? what am i doing…
user285594
13
votes
5 answers

In BASH, How do i replace \r from a variable that exist in a file written using HTML

How do i replace the \r? #!/bin/bash ... # setup if [[ $i =~ $screen ]]; then ORIGINAL=${BASH_REMATCH[1]} # original value is: 3DROTATE\r AFTER =${ORIGINAL/\\r/} # does not replace \r myThirdPartyApplication -o…
user285594
12
votes
1 answer

Unable to enable globstar in Bash 4

I put the following unsuccessfully to my .bashrc shopt -s globstar I am trying to test the command in action by ls **/*.c and by comparing it to ls */*/*.c How can you enable globstar in Bash 4?
Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697
11
votes
4 answers

Bash RegEx to check floating point numbers from user input

I'm relatively new to bash programming and i am currently creating a simple calculator. It needs to use floating point numbers and check they are so. I have a checkNumbers function: function checkNumber { regExp=[0-9] if [ $testNo =~…
Sam_Web
  • 125
  • 1
  • 2
  • 7
10
votes
2 answers

place a multi-line output inside a variable

I'm writing a script in bash and I want it to execute a command and to handle each line separately. for example: LINES=$(df) echo $LINES it will return all the output converting new lines with spaces. example: if the output was supposed to…
ufk
  • 30,912
  • 70
  • 235
  • 386
8
votes
4 answers

Simple Bash and RegEx Questions

I'm unable to get a pattern to match properly using regex in bash 4.1. I've read some information on about differences in quotes vs not quotes but I don't think that is my problem. My goal is to check and make sure that the script is provided a…
Gray Race
  • 195
  • 1
  • 1
  • 5
7
votes
1 answer

Capitalize first letter of string in Makefile using bash 4 syntax

In bash 4 (and above), to capitalize the first letter of a string stored in variable L1, I can do the following: L1=en Ll1=${L1^} echo $Ll1 This prints En. I'm trying to do something similar within a Makefile, but I can't get the ${L1^} syntax to…
Proyag
  • 2,132
  • 13
  • 26
6
votes
1 answer

Associative array in bash not storing values inside loop

This is my $a output: [root@node1 ~]# echo "${a}" /dev/vdc1 /gfs1 /dev/vdd1 /elastic mfsmount /usr/local/flytxt I gotta store these in an associative array fsmounts with first column as keys and second col as value. This is my code for that: …
Akhil Nair
  • 117
  • 6
6
votes
2 answers

How is bash scripting affected by the bash4 release?

bash4 looks good on paper, and I think I'll build it and give it a test drive. In the meantime... Anyone who has done the same care to share their expierence? It would be particularly interesting to hear of any issues with old bash code.
martin clayton
  • 76,436
  • 32
  • 213
  • 198
5
votes
2 answers

What ncurses frameworks are available for BASH?

Are there some more Text User Interface (TUI) frameworks for bash (other than this)? : http://code.google.com/p/bashsimplecurses/ I want to take user input (data entry) process the entry
user285594
5
votes
4 answers

How to change current working directory inside command_not_found_handle

I'm trying to write a not found handle in Bash that does the following: If $1 exists and it's a directory, cd into it. If $1 exists inside a user defined directory $DEV_DIR, `cd into it. If the previous conditions don't apply, fail. Right now I…
Federico Builes
  • 4,939
  • 4
  • 34
  • 48
5
votes
2 answers

The equal tilde operator is not working in bash 4

In a server with bash version 3 I do this: bash3$ e="tar xfz"; [[ "$e" =~ "^tar" ]] && echo 0 || echo 1 0 But when I execute the same command in bash version 4 bash4$ e="tar xfz"; [[ "$e" =~ "^tar" ]] && echo 0 || echo 1 1 I tried it in CentOS,…
1
2 3 4 5 6