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

3
votes
4answers
366 views

How can I make a bash script that determines if a program is already running

There is a python program I am making, and I am planning to have it launch via a bash script. However the program acts badly when the computer tries to launch it twice. Since I really only need this ...
1
vote
3answers
68 views

Shebang does not set SHELL in cron

I have a script containing: #!/bin/bash printenv When I run it from the command line: env testscript.sh bash testscript.sh sh testscript.sh every time, it outputs SHELL=/bin/bash. However, when ...
2
votes
2answers
84 views

How to remove a file that can be seen but no program can seem to touch?

I'm trying to remove some obsolete backups, and deep inside one I've found a file 'cifs3bee' that I can find no way of removing. (And since I can't remove it, it's preventing the removal of the entire ...
2
votes
1answer
61 views

Interrupt bash infinite while loop with read

So, this is admittedly a contrived example and it comes as a result of trying to create a series of bash commands that can be executed in such a way that there is no way to resume control of the ...
3
votes
1answer
49 views

Pass 'typed text' from bash interactive shell to a command

The idea is to pass whatever the user has typed in a bash shell to a command when the user presses a keyboard binding|shortcut For example : Lets say Ctrl+b is our binding bind '"\C-b": ...
0
votes
0answers
30 views

How can I ignore errors in the ls command? [duplicate]

I have this command, that lists how many job files I have running ls -las /var/www/data/forked/jobs/j*.job | echo "Jobs: $(wc -l)" However, if there aren't any, it throws an error. What's the ...
1
vote
2answers
50 views

`ip addr` in one-line per interface

I would like to print specific information about network configuration for different interfaces over all the servers I manage: the interface name the interface ipv4 address the interface hardware ...
1
vote
2answers
35 views

How to interrupt uninterruptible program?

If I run mysqld from the command line, it displays some startup messages, and then stops responding. It doesn't produce output, and ignores any input, and there seems to be no way to get rid of it. ...
1
vote
0answers
26 views

Can't get bare-bone simple bash function to work [closed]

I have some tmux scripts in a directory, and I'm trying to make a script to make it easier to call them. Function is below tms() { ~/linux/scripts/tmux-scripts/$1 } This is in my bashrc, I then ...
2
votes
1answer
40 views

rsync over SSH sometimes very slow--other times maxes out bandwidth

I have a bash script set up on computer A (Mac OS X) set to run every five minutes via a cronjob. This script checks for new files on remote computer B (Gentoo Linux) then rsyncs any new files to ...
1
vote
1answer
47 views

Disable sorting of COMPREPLY in bash complete function

I have a list of words that should be present in the order of appearance in completion to a certain key, but bash seems to be internally sorting what is assigned to COMPREPLY array. How to avoid that? ...
0
votes
2answers
35 views

Cannot login after making a service autorun at startup [Debian]

On a normal startup after booting the login prompt appears from where I would login. But after making motion autostart I am unable to login or open GUI because motion is using the command line to ...
2
votes
3answers
45 views

Garbage in bash session log file. (using script command)

I tried to log bash session using: js:/var/tmp # script -aqf /var/tmp/out In out file I see, besides output, a lot of garbage. Instead of just whitespaces and new lines I see this, for example: ...
-3
votes
2answers
35 views

Relate data in a file

I have a file with a huge data organized in columns, I want to extract the number of data in the first column, that have the same value in column #18.
0
votes
1answer
28 views

Remove duplication from two compressed files

I have two compressed files, with values organized in columns. I need to check the first column in each one, and delete the duplicated values from the first file, and keep it in the second one. Any ...
0
votes
3answers
43 views

Shell append string after last match

I would like to insert a string after the last match, example: String to insert after last instance of banana: Orange Input Apple Banana Apple Banana Output Apple Banana Apple Banana Orange I ...
0
votes
1answer
28 views

Auto Download & Untar Script

Looking to write a script for my Linux Server so look for a specific folder name, then wget a file, and untar. Where would I start with this? I know that it has to be written in bash, but I'm very ...
4
votes
3answers
146 views

Bash script: do something one time inside a loop then stop, but continue looping

I have a Bash script that checks my laptop battery and sends me an Android notification (via shuttle, a Bash script I wrote that serves as a cli interface for the Pushbullet API). It works nicely, but ...
1
vote
3answers
30 views

Match hexadecimal values in a case statement

I'm trying to match exit codes of a process that is documented to return hexadecimal exit codes (e.g. 0x00 for success, 0x40 - 0x4F on user error, 0x50 - 0x5F on internal error, etc.). I'd like to ...
0
votes
0answers
54 views

extract text to csv file from output of reading multiple files into specific rows

I am trying to write a bash script to generate a csv file from text within multiple pdf documents. I have a script for converting pdf to text, but not for generating the csv file. Each text document ...
3
votes
2answers
47 views

Create thumbnail from video at random time frame

I'm using this bash script to generate thumbnails from videos: #!/bin/bash source_dir="." output_dir="/output" input_file_types=(avi wmv flv mkv mpg mp4) output_file_type="jpg" r1=$(( ( RANDOM % 10 ) ...
6
votes
1answer
57 views

Is it possible to add a process to the job list in bash (e.g. to reverse “disown”)?

If I disown a job in bash and change my mind, can I undo it somehow ? If so, taking it further, is it possible to bring an arbitrary process under job control (an acceptable restriction would be that ...
1
vote
1answer
34 views

bash/gnu readline multiline command: move row up/down

How to move one editing row up (back) or down (forward) in a multi-line command in bash/readline? Somethnig like gj/gk in Vim.
3
votes
4answers
216 views

Processing array values in bash

I am trying to create an array based upon filenames, and get in trouble with whitespaces. This seems common. But - as far as I can see - the quotes are set correctly, I guess it must be the way the ...
0
votes
1answer
42 views

ln -s removes part of a a file name, filename passed as a var

I use a script to link some of the files I download to a different directory. When there are "-" in the file name, ln - s wont read the path correctly, even though the variable will be logged ...
2
votes
0answers
22 views

Data written to /dev/pts/x inside SIGINT (Ctrl+C) handler is randomly discarded [on hold]

Have Archlinux64 on VirtualBox. If I declare a SIGINT trap like this: trap 'echo x' INT inside an ssh session (running bash) and press Ctrl+C multiple times, only a few times does something appear ...
5
votes
0answers
26 views

Bash: How to avoid variable name substitution when using auto-completion?

I'd like Bash to stop removing variable names from paths and replacing them by their values. I tried several 'shopts' settings in various bash versions but was not successful in keeping a variable ...
3
votes
7answers
149 views

for loop in bash lists dot and double dot folders [duplicate]

for f in ~/common/.*; do echo $f done The entries listed are, /home/sk/common/. #undesired /home/sk/common/.. #undesired /home/sk/common/.aliasrc And i am putting a ugly ...
3
votes
3answers
103 views

What is the difference of defining a variable with or without quotation marks? [duplicate]

If I define a variable with the quotation mark: TEMP="~/Dropbox" then ls $TEMP would not work, instead echo $TEMP | ls works. And to get the same result, I can also define the variable ...
2
votes
1answer
42 views

What's the purpose of -i and -s options of bash?

It seems that either I don't understand what these options mean, or bash behaves the same (as interactive shell that reads standard input) without any options anyway. When would I want to use these ...
4
votes
1answer
84 views

How does the “subl” command work?

To open a file to edit in gedit I run gedit sample.py &. But with Sublime Text it is simply subl sample.py. This opens the file to edit and it doesn't run in the background (in my shell). How ...
1
vote
5answers
84 views

How to get all numbers out of a string and add them?

I have to parse a .xml file generated to summarize the results of a running a testSuite on some software. In a line I have, for example: <Summary failed="10" notExecuted="0" timeout="0" ...
2
votes
2answers
48 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
29 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
346 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
236 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
52 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
38 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
36 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
56 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
49 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 ...