Questions specific to GNU’s Bourne Again SHell, as opposed to other Bourne/POSIX shells. For questions about Unix shells in general, use the /shell tag instead.

learn more… | top users | synonyms

21
votes
3answers
31k views

dircolors: modify color settings globaly

I understand ls uses dircolors to display colored output. dircolors has default database of colors associated with file extensions, which can be printed wiht the command dircolors --print-database ...
1
vote
2answers
542 views

Subprocesses of bash/gnome-terminal don't terminate (CentOS/RHEL)

today I observed something which probably has an easy explanation, but was quite quite unexpected from my side: I'm running CentOS (and RHEL which behaves same). I open a bash in a terminal and start ...
4
votes
1answer
3k views

Less-than sign after done in a shell script

Should be easy but want to know why the “left arrow” < is used instead of right arrow. if fi done < a.txt What does it mean by left arrow? I thought since I am done with the ...
0
votes
2answers
2k views

Shell, bash, linux : after variable declaration, why semi-colon and what does it do?

Here is the line. variable=`ls -A $1 | grep '[abc]'; ls -1 $1` I understand the line before the semi-colon but I do not understand how this line works after semi-colon. Does it after the ...
0
votes
1answer
18k views

$1 means for … ? without any input?

I have one program that starts with this line. What does this mean? I am having trouble googling because of the dollar sign. How come $1 without any parameters? And what does it mean by -d here? ...
4
votes
5answers
3k views

How to use filename arguments or default to stdin, stdout (brief)

I want to handle filenames as arguments in a bash script in a cleaner, more flexible way, taking 0, 1, or 2 arguments for input and output filenames. when args = 0, read from stdin, write to stdout ...
1
vote
1answer
2k views

Script ends abruptly with a Terminated message

This is my bash script. All it does is to check whether a service has started and whether some processes are running as expected. It ends abruptly with a Terminated message. I tried debugging it ...
1
vote
3answers
598 views

splitting the string in bash script

I am new to bash script. I am taking some input from user and checking details about that. Example: $HOME/Documents/test/one.txt I take the above string as an input and want to retrieve one.txt, I ...
8
votes
4answers
4k views

Recursively add a file to all sub-directories

How do I recursively add(or touch) a file into the current directory, as well as all sub-directories? For example, I would like to turn this directory tree: . ├── 1 │   ├── A │   └── B ├── 2 │   └── ...
2
votes
3answers
323 views

Concatenate files in multiple matching subdirectories

I need to concatenate files based upon the name of the subdirectory they are in. The subdirectories sometimes have duplicates and sometimes don't. The file structure looks like this: RootDir 633 ...
4
votes
4answers
445 views

How do I aggregate data from many files into one file?

I have this directory structure for about 100 users. users - user1 - info.txt - user2 - info.txt - user3 - info.txt ... Inside the info.txt files, the contents look like this. 5 ...
4
votes
1answer
1k views

Cowfiles directory?

My bashrc issues a cow from cowsay and with a random fortune. Like this: echo -e "\e[00;33m $(fortune -a -o -s | cowsay -f $(ls /usr/share/cowsay/cows/ | shuf -n1) | sed -e 's/^/ /g')\e[00m" ...
10
votes
4answers
13k views

How to convert a color pdf to black-white?

I'd like to transform a pdf with some coloured text and images in another pdf with only black&white, in order to reduce its dimensions. Moreover, I would like to keep the text as text, without ...
3
votes
1answer
223 views

Build bash (or alternate linux package) with custom binary/doc name

I am trying to build Bash 4.2 as an RPM package for use on Enterprise Linux 5 systems, which come by default with 3.2.25. This works successfully, however, I want both versions to co-exist on the ...
3
votes
2answers
476 views

bash: get array name from parameter to function with saving indexes

I have a function to show index of chosen element. I'm trying to pass a parameter to function to use it as an array name. This works: getIndex() { arrname=$1[@] b=("${!arrname}") index=1; while ((...
5
votes
2answers
2k views

Can't apply brightness to terminal's background color

I have a problem with colors in my terminal emulator. I am using LXTerminal as my terminal emulator and LXDE as my desktop environment. The following command is supposed to print red text on grey ...
6
votes
3answers
14k views

search text on the terminal output

I am running an application with command $ grails run-app which prints log in terminal like below. What I want is search a particular text (say user authorities) in this log so that I can verify ...
1
vote
3answers
437 views

Reversing the value key pairs of array using sed or pattern replacement or brace expansion?

#!/bin/bash arr=(a b c d) declare -A brr for i in ${!arr[@]} do brr[${arr[$i]}]=$i done echo ${brr[@]} #0 1 2 3 Is there any way to reverse the values and key pairs ...
2
votes
4answers
2k views

how to convert number to time format in shell script?

I want to cut a video into about 10 minute parts like this. ffmpeg -i video.mp4 -ss 00:00:00 -t 00:10:00 -c copy 01.mp4 ffmpeg -i video.mp4 -ss 00:10:00 -t 00:10:00 -c copy 02.mp4 ffmpeg -i video.mp4 ...
3
votes
1answer
622 views

hanging ssh processes launched from a script

i am creating a few vms through a script. as a part of it, i am changing the names of the vms using ssh. for some reason when i run the below command for three vms it works and for the magic number ...
5
votes
1answer
779 views

Perl and Python wrongly interpreted via shebang on Linux

that problem just drives me crazy. All my Python and Perl scripts are simply NOT iterpreted via shebang. Never. But they work as expected when I explicitly call the binary. I double checked my ...
4
votes
1answer
8k views

How to assign result of sed to variable

Below is a complete copy of a demo I'm using to to figure out to get the sed command to get rid of the spaces in a persons name, and compress it down to not have spaces. Once this is done, I want to ...
3
votes
2answers
670 views

BASH and Subshells

From what I gather from the online docs, the following should spawn a subshell for the part of the command embedded with {}: $ bash -c '{ sleep 10; echo "Sleeping process", $$; } & echo $$; ' ...
0
votes
1answer
54 views

Can anyone help me in leaning bash scripts? [closed]

I want to learn bash scripting on Linux. Can anyone provide good links for starting bash scripts?
0
votes
1answer
134 views

API for panel applets on eOS Pantheon?

Is there any API (esp python or bash) to append new applets on eOS Pantheon's panel? I can't find proper documentation.
1
vote
1answer
207 views

What is the use of ; in a single line command?

What does ; mean in single line scripts like this: while true; do sudo -n true; sleep 60; kill -0 '$$' || exit; done 2>/dev/null & Does it mean new line, or "next command"?
6
votes
1answer
253 views

What is the difference in these two bash environments?

I notice that with bash scripts, some people use a different shebang to the one that I'm used to putting at the top of my own. Can someone simplify the difference between these two? I use the #!/bin/...
0
votes
2answers
107 views

Why must you be careful when using Bash's built in command history function to re-run previous commands that contain variables?

I know !! re-runs commands but what exactly would occur if I re-ran a command that had a variable in the command?
11
votes
2answers
12k views

Regular expression in bash script

This is my first time bash scripting so I'm probably making an easy mistake. Basically, I'm trying to write a script that gets the groups of a user, and if they are in a certain group, it will log ...
2
votes
3answers
100 views

Is it a good idea to put environment variables to /usr/local/bin

I'm using aws cfn to start ubuntu instances, and I need to pass variables provided in cfn launch script to the scripts on the instance. For example, I may pass "db-server=db-2.domain.com" and there is ...
11
votes
2answers
42k views

List subdirectories only n level deep

Festival stores voicepack data in the following example directory structure: /usr/share/festival/voices/<language>/<voicepack name> What is the simplest one-liner (preferably using ls) ...
0
votes
1answer
1k views

LD_LIBRARY_PATH not found - CentOS

I am trying to run the following two commands... LD_LIBRARY_PATH =/opt/oracle/instantclient_12_1 export LD_LIBRARY_PATH But when I run the first command I get an error -bash: ...
2
votes
2answers
411 views

Sanitize Apache access log files?

We have this code in a shell script that pipes output for Apache to log. declare -a values=( $taintRequestVals ) for item in ${!values[@]} do cat $apacheLog | sed "s/${values[$item]}=[^&\t\...
4
votes
3answers
302 views

dash reports 'Syntax error: “(” unexpected' when using process substitution

I have following bash command diff <(xzcat file1.xz) <(xzcat file2.xz) and I need to execute it in dash. On my system (Debian Wheezy), dash is the default interpreter for cron (/bin/sh is a ...
3
votes
2answers
3k views

bash PS1 256 colors with bold

I want to list all colors that I can use in bash console. And after it I want to set my prompt to be bold and orange like color. I'm using this to do listing color codes for me: for code in {0..255}; ...
1
vote
1answer
105 views

vim flag to append a line and save

I'm trying to mock an editor as part of writing feature tests for a CLI that I'm working on. I need to mock an editor which is opened and quit directly without saving, as well as an editor which ...
1
vote
1answer
246 views

How can I reset the bash filename completion for “more”?

I've done something that has changed the way TAB auto-complete works, but only for the more command. Every other command lists the possible completions, but more now lists ALL of the possibilities ...
1
vote
2answers
310 views

Why does this not work when the load average exceeds 1?

I have been testing this script and its behavior has been odd. The script should generate notifications whenever the load average exceeds a specified limit. Whenever I pass a CPU_LOAD_LMT >=60, no ...
5
votes
3answers
448 views

how to prevent exported environment variables to be recognized/accessible by a child shell (bash)?

So, I need to prevent loads of exported variables to be recognized by a child shell. The problem is an application (Wine+UDK) wont build projects with too many (>65535) bytes on the environment, ...
22
votes
4answers
97k views

how can I add (subtract, etc.) two numbers with bash?

I can read the numbers and operation in with: echo "First number please" read num1 echo "Second mumber please" read num2 echo "Operation?" read op but then all my attempts to add the numbers fail: ...
0
votes
1answer
831 views

List of special characters in the shell [closed]

I am not sure what they are called, but where could I find a list of wild cards? I see things like: $f %s $1 Is there a definitive list for what each one represents?
3
votes
3answers
7k views

How can I keep *all* environment vars for a specific command in sudo?

I have a script that sets several environment variables and then finally calls another script using sudo. The script run with sudo must be able to pick up those variables, and I'm not always going to ...
8
votes
2answers
2k views

What does this ${@:2} mean in shell scripting

I see this in a shell script. variable=${@:2} What is it doing?
1
vote
1answer
476 views

Is there a simple way of limiting the number of child processes that execute in parallel?

I have a bash script that kicks off multiple rsync processes in parallel. I'd like to limit the number of simultaneous child processes but not serialize the whole script. Here's a simplified version ...
7
votes
2answers
5k views

Use the command bar in bash without I/O?

I really like the look of the output of bar But that script is only used for Input/Output operations. How can I use it as a replacement for sleep but with visual feedback? sleep 10
4
votes
4answers
11k views

Progressbar in bash to visualize the time to wait

In a bash script sometimes you need the user to wait some seconds for a background process to finish. I usually use for example: sleep 10 How can I add a kind of progressbar to the script, so the ...
1
vote
3answers
2k views

cron: bash syntax not working

I am trying to add following command to crontab: I=1; for X in $(/bin/ls -r /var/tmp/*); do [ $((I++)) -le 28 ] && echo "lower" || echo "higher"; done When executed on the command line (in ...
0
votes
1answer
1k views

List of 'if' switches anywhere? [closed]

Is there a list of all the if switches for use in bash scripting? Sometimes I see someone using it and I wonder what the switch they're using actually does. Example is the -z in this one. I know how ...
4
votes
3answers
921 views

Bash, name of the stdin file?

I have to write a bash script which will count symbols like "<" and ">" from stdin. For example: $ ./myscript.sh <example.html > - 20 < - 21 Found mismatching brackets! I did this: x=`...
15
votes
2answers
488 views

bash_history: comment out dangerous commands: `#`

To prevent logging "dangerous" commands in bash history, I have added following line to my .bashrc file: HISTIGNORE='rm *:mv *:cp *:cat*>*:pv*>*' this works well, but it has a side effect: I ...