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
2answers
93 views

how to re-use existing completion with recent bash-completion?

i use alias which adds some parameters to some program. for example: alias git.home='git --git-dir=$HOME/.git.home/' complete -o bashdefault -o default -o nospace -F _git git.home \ ...
24
votes
4answers
5k views

How do you use the command coproc in Bash?

Can someone provide a couple of examples on how to use coproc?
2
votes
1answer
105 views

I/O redirection shortcut doesn't work when at the end of a command line

I've been getting myself comfortable with I/O redirection. I've become aware of the &> shortcut for 2>&1. I believe it also works as >&. There may be a nuance to that of which I'm ...
0
votes
0answers
23 views

Starting a script when a certain usb is inserted problems

I want to start a script when a certain usb flash drive is inserted. I had a python script in my home folder "test.py", I ran lsusb and found the vendorid and productid, I went to udev and made a rule ...
3
votes
3answers
105 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 ...
4
votes
2answers
581 views

How can I copy all users .bash_history files into my home directory?

I am running as root. I want to copy all the users on the system's .bash_history files into my home directory. I can do this to combine all of them into one, but then I can't tell who's commands are ...
0
votes
1answer
45 views

Bash command to source a file in a different directory?

I have a collection of bash scripts and I want to put some common shell options and variable declarations into a "setup.sh" script which would get sourced at the beginning of each script. my directory ...
2
votes
1answer
73 views

When i run “sudo su” i get --bash: command not found for everything

I'm not good with command lines nor servers. But I needed to configure for work a AMI of EC2 AWS with LINUX So I've installed a lot of stuff, moved a lot of stuff around and then I realized that sudo ...
5
votes
0answers
27 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 ...
2
votes
2answers
47 views

How to move files to files with same name, but different extension

I have a folder A with many small files. In the parent folder there are many folders with other files in them. now in folder A there are files that have the same name as in the other folders, but they ...
0
votes
4answers
3k views

Zenity dialog windows have excessive height and cannot be resized. Bug workaround anyone?

I'm trying to do some things in zenity, and it's been driving me bonkers. To illustrate my problem, try running this: zenity --info --text "Hello there friends." Simple enough right. Now try this: ...
10
votes
7answers
20k views

How to read first and last line from cat output?

I have text file. Task - get first and last line from file after $ cat file | grep -E "1|2|3|4" | commandtoprint $ cat file 1 2 3 4 5 Need this without cat output (only 1 and 5). ~$ cat file | ...
1
vote
1answer
47 views

Why does bash parameter expansion not work inside systemd service files?

I am trying to use systemd's EnvironmentFile and add an option to the command when it is set in the file. I have the following in the unit file: ExecStart=/usr/bin/bash -c "echo ${PORT:+port is ...
0
votes
2answers
27 views

“Replace” default shell (bash) with tmux

Background: An co-worker at my company uses tmux all the time, in our spare-time he teached me mastering tmux and vim and I really fall in love with the power of this combination. Currently, I am ...
-1
votes
1answer
28 views

modify perl output [closed]

currently I have the following script #!/usr/bin/env perl use strict; use warnings; my %seen; my $header = <> . <>; print $header; my $last_sequence_number = 0; open( my $output, ...
3
votes
1answer
43 views

Get return value from `find .. -exec ..` command?

In a bash script, I have a function that does some processing on the argument passed to it. I'd like to set a return value depending on how the processing went. Problem is that the function is called ...
3
votes
1answer
39 views

Condition on finding a file

I'm trying to write a script which looks for a file and if it is found, saves the full path to a variable. Current version: if [[ -n FOUND_PATH=$(find "$PATH" -name "file.exe") ]]; then echo ...
0
votes
1answer
62 views

load bash comands from file one per line and execute them for each file in a directory

I'm trying to write a bash queue which will be able to load command set from a file and then execute each over set of files. prepared file should serve as a template for execution in manual bash ...
33
votes
8answers
56k views

How can I get the size of a file in a bash script?

How can I get the size of a file in a bash script? How do I assign this to a bash variable so I can use it later?
-1
votes
0answers
38 views

random shuffle and extracting all the grouped records

The question is different than what is being asked earlier: so, pls coordinate I have a data set that looks like 1616.93,ac:22:0b:a6:22:c3 2872.32,c0:bd:d1:36:bb:49 3314.55,d4:0b:1a:39:19:b2 ...
3
votes
2answers
30 views

Setting variable with default value behaves differently when preceding a command?

Setting a variable with a fallback default value works...as long as we're using the variable in a subsequent command: $ unset APP_ENV $ echo $APP_ENV $ APP_ENV="${APP_ENV:-production}"; echo ...
0
votes
1answer
43 views

Numeric test in bash: integer expression expected

I created a simple script in bash language to do cleaning of the recycle bin in Ubuntu. here is the script "recycle.sh" #!/bin/bash PUBLIC_PATH="/home/fileserv/.recycle/Public" ##### Clean public ...
0
votes
1answer
14 views

Bash overwrites the first line when using custom PS1 prompt [duplicate]

My question is similar, but different to, this question. I have created a custom PS1 in my .bashrc, as follows: STARTCOLOR='\e[0;36m'; ENDCOLOR="\e[0m" export PS1="\n$STARTCOLOR\u@\h:\! <\t> ...
1
vote
2answers
23k views

“not a valid identifier” when I do “export $PATH”

When I run export $PATH in bash, I get the error not a valid identifier. Why?
1
vote
1answer
17 views

Why does using rev as your man pager fail when piping it through rev again?

I recently thought about a devious trick that involves setting the PAGER envionment variable to rev as a joke. When I tried reading the man page for rev with man rev I then saw the man page in reverse ...
0
votes
2answers
691 views

VLC script on ubuntu server

I need a small script which run three vlc command on the same time (on Ubuntu server 14.04) as stated below: #!/bin/sh cvlc -vvv v1 --sout ...
1
vote
2answers
563 views

Read line from file then delete

How can I read a series of lines from a file and then remove each line? Obviously I can read like this: while read -r line; do echo $line done < myfile.txt But if I do this: while read -r ...
7
votes
4answers
3k views

redirect and log script output

I am trying to tidy up the following snippets, design goals are to log all output from a script, and should not be a wrapper. Less lines are better. I don't care about user inputs (at this stage), ...
0
votes
1answer
32 views

Redirect stdin for multiple shell functions [closed]

I'm surprised nobody has asked this before - maybe I'm just that dumb? How to I force this script to do what I intended? #!/bin/bash function One() { IFS='' read -r -n1 CHAR echo "One: '$CHAR'" ...
32
votes
7answers
10k views

How to debug a bash script?

I'm having some problems with some scripts in bash, about errors and unexpected behaviors. I would like to investigate the causes of the problems so I can apply fixes. Is there a way I can turn some ...
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 ...
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
1answer
23 views

How do I prevent the Keyboard Interrupt from being sent through the Screen program

I am making a python program, whose output (not input) can be viewed via the screen program. However, the problem is that doing this allows the user to turn off the program via the Keyboard Interrupt ...
3
votes
4answers
369 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
70 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 ...
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 ...
2
votes
3answers
840 views

Match a single character in a string bash script

My issues is that I want to read a character from the stdin and compare it with a string value. If that character exists then I want to display a message. Eg, saving % into the variable $a: $ read a ...
0
votes
0answers
36 views

How to put the current working directory into the PATH variable

Is it possible to put the current working directory into the $PATH variable? Perhaps something like: me@hostName:~$ echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/$(PWD) ...
1
vote
1answer
27 views

Handle wildcards matching no file in bash

I am trying to read files from a directory into an array but even when the file doesn't exist, its saved in array. I want to exclude the file name if it doesn't exist. a=(/tmp/nofileexists) ...
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": ...
1
vote
3answers
31 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 ...
2
votes
2answers
87 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 ...
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 ...
0
votes
0answers
56 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
4answers
2k views

How can I open a file that results from grep?

I often grep a bunch of files to find a line, and then grep returns one result. Rather than copying and pasting the filename into a new command, I'd like to be able to open that one result with an ...
3
votes
4answers
221 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 ...
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 ...
4
votes
3answers
148 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 ...
0
votes
1answer
811 views

mailx: nss-config-dir=/etc/pki/nssdb/: No such file or directory

I am trying to send email using mailx using remote SMTP server (in my case it is office365 SMTP Server). Here is the command: # echo "THis is the Body of the email" | mailx -v -s "This is email ...