Questions about bash only, as opposed to other Bourne/POSIX shells. For all Bourne/POSIX-style shells, use the /shell tag instead.

learn more… | top users | synonyms

2
votes
2answers
49 views

remove whitespace from all items in a directory and sub directory

I have a directory which contains files and sub directories, some of which have whitespace in their names. Further more each of these sub directories contains files with whitespace in their names. Is ...
2
votes
1answer
32 views

Can we broadcast in tmux

Now we know that we can do a broadcast all or to a specific group in terminator and execute commands simultaneously on every window. Can we do the same inside a tmux session?
1
vote
3answers
69 views

Bash convert string to array of strings?

I've got a string like this: 8080 "ac ac df asd" 9019 "f v adfs" 1 "123 da 123x" Is there a clever way to convert this into arrays like this using Bash? 8080 "ac ac df asd" 9019 "f v adfs" 1 "123 ...
1
vote
1answer
26 views

Bash script only runs in debug mode [closed]

I have the following bash script: #!/bin/bash -e SUDO=sudo $SUDO apt-get -y update || true $SUDO apt-get -y install lxc bridge-utils || true # remove the default bridge, if it exists ...
8
votes
4answers
352 views

How to assert that a string has a newline character and, if so, remove it

I have a string that is the result of some operation I have no control over. When I print this variable using echo, I get: echo $myvar hello However, when I do if [ $myvar = "hello" ]; then ...
1
vote
1answer
40 views

Recursively count occurrences of a word in identically named files in different directories

I've got several different directories that contain different versions of some files. I want to count a symbol in all versions of the same file. Here is an example of the hierarchy. directory ...
4
votes
2answers
242 views

New line in bash variables

I'm trying to store multiple lines in a bash variable, but it doesn't seem to work. For example, if I list /bin one file per line and store it in $LS, then I pass $LS as stdin to wc, it always ...
0
votes
4answers
53 views

How can I go to the directory at certain depth in the current tree?

I generally work on within multiple folders (dev1, dev2 and dev3) in the same server. The folder structure is something like: /var/www/html/dev1/a/b/c/d/e/f /var/www/html/dev2/a/b/c/d/e/f ...
0
votes
1answer
18 views

Compile freedink couldn't find SDL2

I tried to compile GNU Freedink as described in the BUILD file but when I try to configure it couldn't find SDL2. Log: http://pastebin.com/GYHHa4T0
0
votes
3answers
66 views

How to achieve “continuos randomness”?

With RANDOM%xone gets a set of discrete results. How can I achieve following scenario?: Inside a for loop, I'd like to let a bash script execute command A in 33.33% of all loops and else execute ...
0
votes
1answer
39 views

Bash if statement not working properly [closed]

I have a bash statement to test a command line argument. If the argument passed to the script is "clean", then the script removes all .o files. Otherwise, it builds a program. However, not matter what ...
0
votes
0answers
5 views

Fine tuning of an informative replacement for rm [migrated]

I want to replace rm by a more informative variant: I would like to see which files will be deleted, along with their size, and I would like this information to use the same coloring as ls. I built ...
0
votes
1answer
37 views

How do I exec more than one command?

My login script ~/.profile ends with the command exec startx > ~/.xsession-errors 2>&1 I would like to run a second command foo when startx is done so I tried exec { startx > ...
0
votes
1answer
19 views

Redirect all GnuPG output to /dev/null

I'm doing key generation in a sort of batch mode with GnuPG (don't ask why): echo -e 'addkey\n4\n2048\n120d\nsave' | gpg --command-fd 0 \ --edit-key $master_key_id >/dev/null 2>&1 I ...
4
votes
3answers
58 views

Go from a String to an Array of “words” in Bash

I need to go from a string to an array where each entry is each word on that string. For example, starting with: VotePedro="Vote for Pedro" I need the array: Vote For Pedro Which I should then ...
3
votes
3answers
50 views

Wait for key in shell script that may get piped to /bin/bash

Consider the following shell script echo foo; read; echo bar Running bash my_script outputs 'foo', waits for the return key and outputs 'bar'. While this works fine running it that way, it doesn't ...
1
vote
1answer
50 views

Exiting a script called from another script via SSH

Suppose that bash script X is being called within another bash script Y. If I directly execute script X on a local machine, after X's completion, the program exits to the terminal. However, when I ...
0
votes
1answer
26 views

Running a command on different shell

While reading the answers of question Can bash write to its own input stream?, I found following command runs on zsh but not on bash : print -z echo mnciitbhu 1 . Is -z is an extension to print ...
2
votes
4answers
113 views

How to influence a bash while loop with a timed global variable?

I have a while loop in a bash script which should do something different at the beginning and at every 5 second interval. Any previous loop is allowed to complete. The 5s interval is indicated by the ...
0
votes
1answer
72 views

How to run multiple sudo commands over already opened ssh connection

I am trying to navigate from one server"USER1" to another using ssh as a user "USER2". ssh -t $hostname "sudo su - USER2; whoami; pwd" Post executing the above, I am able to successfully navigate ...
0
votes
1answer
33 views

Need to parse nginx access.log by minute, chunks for statistics - is there better way?

I need collect current data from it every minute to monitore amount of requests and errors. It's nginx's frontend log - with a lot of requests. It's formatted, rotated than archived every hour. So - ...
1
vote
1answer
58 views

What does colon (':') in bash variable resolution syntax mean? [duplicate]

Could you help me decode this assignment: jvm_xmx=${jvm_xmx:-1024} Can't understand, what it does.
2
votes
2answers
82 views

What is the shortest way to select the first available port in a certain range using Bash?

Aim: Select the first available port in a certain range. E.g., if port 600 is unavailable then the availability of port 601 will be checked. Attempt: The following script works as expected but is too ...
0
votes
1answer
32 views

PS1 variable inheritance between scripts and programs using bash in AIX

How to ensure that PS1 variable in AIX bash is inherited between cross calling of scripts and programs ? Suppose a program that give to the user a shell instance like the shell command of vi. This is ...
0
votes
1answer
52 views

What does PROG=${0##*/} mean in a bash script? [duplicate]

PROG=${0##*/} seems to parse out the shell script name, but it's unclear how that works. ${0} I understand is the first or 0th variable.
2
votes
2answers
45 views

How do I kill a process after detaching it from bash?

I have multiple scripts that detach a process from bash using nohup and &>/dev/null &. My question is, how do I kill the process after completely detaching it from bash. using killall or ...
1
vote
0answers
20 views

Build Script Help, Not Loading Modules

So I am writing a script to build and install Netcdf, but when I source it, it seems like some of the lines just are not running or are being skipped and I am unsure why. When I run the code line by ...
1
vote
5answers
115 views

list all files with extension .log except one

I would like to list all files with extension .log except the file backup.log. I have tried using this command: ls *.log -I "backup.log" But all the log files are listed, even backup.log! How ...
1
vote
3answers
72 views

Using a function defined in a parent script

I wrote the following script in the test.sh: #!/bin/sh compare() { if [ $1 != root ]; then echo "Fail" >> CAT1.txt fi } awk -F: '$4 == 0' /etc/passwd | cut -d: f1 | xargs -n1 -i bash -c ...
1
vote
1answer
68 views

Using only in-memory command history

How can I prevent Bash from writing history entries to disk? My ~/.bashrccontains the line trap 'unset HISTFILE; exit' SIGHUP but it doesn't have the desired effect. If I run history -c && ...
1
vote
2answers
125 views

Write bash_history to a file with a timestamp

I need help with the script below. The requirement is to capture command line history in a file with specific date and time of commands, when they were executed. The below script captures history ...
1
vote
2answers
217 views

Bash script to read file and echo different lines to output files [duplicate]

I have a log.txt file with various lines of strings and information. I want to write a script to read the log.txt file line by line and any line that contains the word debug I want to put that line ...
0
votes
1answer
16 views

format of a script which installs programs as root, but configures for a regular user?

I am writing some bash scripts to install and configure some programs. Because the script needs to install packages - I run the scripts as root - which itself is no problem (i.e. I have root ...
-1
votes
1answer
74 views

how to extract lines between 2 patterns, and save them to different files

hej all, Let' say that we have this file: rrows 35 cols 51 spin 2 %band5 efermi=0.012538 0.004352 0.004317 0.004213 0.004047 0.003828 0.003570 0.003291 0.003011 0.002754 0.002544 0.002408 ...
2
votes
2answers
78 views

Sort files with a specific extension by modified time and store them into an array

I have found many answers to sort the files of directory and even to save them in an array. Sorting Example ls -t Directory listing in array array=(*) My particular problem needs to sort files ...
0
votes
2answers
93 views

Explain the shell command: shift $(($optind - 1))

I am not a Linux guy but stuck in some Script which I have to read for my Project. So can anyone can help me what this command is doing? shift $(($optind - 1))
13
votes
3answers
575 views

Differentiating between running and being sourced in a bash shell script?

Either what I'm asking here is extremely unorthodox/unconventional/risky, or my Google-fu skills just aren't up to snuff... In a bash shell script, is there any easy of way of telling if it is ...
2
votes
5answers
133 views

Can't login to server with SSH because of a script in /etc/profile.d exiting with exit status 1

so I have this problem, I can't login to my server with SSH. See: ssh -v myuser@myserver debug1: Authentication succeeded (password). debug1: channel 0: new [client-session] debug1: Requesting ...
5
votes
3answers
159 views

Output Output of command to command line directly, NOT variable [duplicate]

I am on the bash shell and I want the output of a command to appear directly in the command prompt that appears after the command has executed ! Example of what I envision it, to illustrate my idea: ...
-2
votes
1answer
44 views

ls: No such file or directory [closed]

I have been messing around trying to install macvim to a higher version of 7.4. I finally got it working but now I get the error ls: No such file or directory when looking for a directory. I can ...
1
vote
2answers
55 views

Exporting a function from .profile/.bashrc

What am I doing wrong...? It's fine if I do this on the command line and then call it but not when I load it from .profile. Linux Mint Qiana, Bash 4.*, if it matters. function android() { command ...
5
votes
1answer
146 views

Logging bash output to a file

I'm trying to build vlc which is rather complicated and dependent on having the right packages installed, and keeps choking on errors. To trace all my steps I wish to output what I'm doing to a ...
11
votes
1answer
308 views

Why Ctrl+m and Ctrl+q wasn't used in bash shortcuts?

Recently I've been viewed through bash shortcuts key, and trying to find an appropriate one for my tmux activate key. And I find an interesting fact that ctrl + m and ctrl + q are not used in bash ...
3
votes
1answer
57 views

Parameter expansion in variable assigned with a wildcard

I have two files in my current folder (MA502) whose names are - MA502_TAAGGCGA-TCGCAGG_L001_R1_001.at.fastq MA502_TAAGGCGA-TCGCAGG_L001_R2_001.at.fastq I have many such folders - ex MA503, MA504 ...
21
votes
5answers
1k views

Can bash write to its own input stream?

Is it possible in an interactive bash shell to enter a command that outputs some text so that it appears at the next command prompt, as if the user had typed in that text at that prompt ? I want to ...
1
vote
0answers
23 views

-devilspie doesn't play nice with spawning new terminals

I'm trying to configure devilspie so that on detection of opening a certain directory it runs a script to mount that directory over a network. I don't think the script itself is too important but ...
2
votes
3answers
54 views

Split command and arguments, and put into variable in a bash script

I have a script that repeats the same (very long) grep command many times. I want to make the script more readable by cutting the line length, so I tried to put parts of the command into variables. ...
0
votes
2answers
64 views

breaking out of command loop but exit code not the reason?

I run the following: echo "while emacs;do echo $?;done;echo Exit code: $?;" | bash If I exit emacs through the menu or the close button, it prints exit code 0 and restarts. If I exit emacs through ...
-1
votes
1answer
42 views

Matching regular expression with delimited string in unix

Can someone help me in matching the below delimited regular expression in bash script: number|my_name|number I have tried the below but could not get it through end: sed -e 's/[^[[digit]]*//g
0
votes
1answer
21 views

Import list of IPs into DEVICE=eth0:X

I have a list of IPs I would like to import into my Linux VPS. They are not an IP range. How would I create a bash script that does this for me? 1.1.1.1 2.2.2.2 If they where my IP lists then it ...