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
1answer
208 views

Loop through a multidimensional array in bash 4

I want to define a hash list in bash (version 4.3.30): 4 gateways each gateway has an IP an IP6 a name ... and I want to walk through this list in a loop and do stuff to each gateway. I ...
2
votes
2answers
92 views

Merge two-columns files into one file

I have a bunch of files (file1, file2,file3, ...) with two columns. For example, file1 looks like: 0.12 0 0.32 0 0.42 1 0.23 0 and file2 looks like: 0.34 1 0.55 1 0.31 1 0.99 0 I wonder how to ...
0
votes
1answer
24 views

Loop commands to network daemon?

I'd like to feed a network daemon using a loop! To be more specific: There is a network daemon listening on localhost:portx. The daemon expects me to guess a PIN between 0000 - 9999. I want to use ...
-1
votes
2answers
38 views

Create shell script to remove certain files from specified directories

I am looking to create a simple script that does the following: cd /specified/directory cd into child directory only if it has a 4 digit name e.g 1234 rm -r all files that begin with letter P rm -r ...
3
votes
1answer
50 views

Possible to pipe command using su via ssh

I'm trying to write a python script to remotely update the login passwords for a set of account I administer - I can already successfully use python to pipe remote commands via the stdin of an ssh ...
0
votes
1answer
49 views

Bash script strange behavior - script does not act as manual commands

So, this is strange. When I manually run commands it all works fine, but when I run a script with identical commands, I get strange error output. This is what I run: lxc list; for elem in ...
1
vote
3answers
33 views

What does it mean to run a process in background? [duplicate]

What exactly does it mean to run a process in the background? The difference between $program and $program&: Is it just that the input file descriptor is not inherited from the shell or is there ...
3
votes
4answers
379 views

Add path to $PATH if not already in $PATH [duplicate]

I need to add a path in a bash script, but it may be executed several times: export PATH=${OPENSHIFT_HOMEDIR}/app-root/runtime/bin/:${PATH} I don't want that path to be added over and over. How can ...
3
votes
1answer
70 views

Bash: Permission denied when trying to echo data directly to Network

I am trying to send characters directly to the network stack as explained in this thread. Even when the process work OK under CygWin (Windows), the same lines do fail on Ubuntu v14.04: ...
0
votes
1answer
9 views

Command Run Differently Depending on How Logged In?

Is there a way to have one command run differently, depending on the manner in which one is logged into the session launching it? Basically, we have a command that when run, launches vim to display ...
7
votes
2answers
65 views

bash: how to propagate errors in process substitution?

I want my shell scripts to fail whenever a command executed with them fails. Typically I do that with: set -e set -o pipefail (typically I add set -u also) The thing is that none of the above ...
1
vote
3answers
32 views

Bash prompt string appears in same line as curl command output

When I run a curl command, the json response that it returns collides with the bash prompt string: ~$curl localhost:8001/api {"message":"this is a test message"}~$ Notice ~$ at the end of second ...
1
vote
2answers
47 views

Returning an variable from a function

I have the Linux script from bellow. I can get to return from the method decrypt nothing in order to unzip a file. The method decrypt sends a string with the name of a zip file. Please give some ...
-8
votes
1answer
60 views

replace the the first line of all .sh files in a folder

Create list of all .sh files in current folder. Check first line of each file in this list and if file starts with #!/bin/sh then replace that with #!/bin/bash. Only modify files that have #!/bin/sh, ...
2
votes
1answer
17 views

How to cancel and keep reverse-i-search?

Often I fail to find something with reverse-i-search but want to keep what I have already written. For example, typing pdflatex fails to complete to pdflatex mydocument.tex. If I then cancel it with ...
-5
votes
1answer
61 views

Find the number of files with sizes

Find the number of files with sizes > 100KB in /, /bin, /usr, /usr/bin and /usr/sbin directories and output them in a two column format with the name of the directory and the number of files.
4
votes
2answers
137 views

Zombies in bash

Bash doesn't seem to create zombies. It looks like the processes get immediately reaped when they get killed. Can I make bash make zombies? Why I'm asking: I'd like to be able to safely kill a ...
3
votes
1answer
35 views

Bash doesn't calculate prompt length correctly

I've googled around quite a bit on this problem and found a few related problems, like this one: Terminal prompt not wrapping correctly. My problem is that bash doesn't calculate the length of the ...
0
votes
1answer
16 views

Problem with inotify-wait as daemon

I have been running inotify-wait on my ftp server in byobu to monitor a folder, move data, and send email notifications for a few months without problems. Since I started this I have added 3 more ...
0
votes
1answer
33 views

syntax error while tring to execute python program in bash shell

I'm trying to use python to read in data from a text file but I keep getting "syntax" errors when I execute the program. Python Code: Test.py import os import numpy as np Ye,Eb,Tb = ...
0
votes
3answers
73 views

Print source code of bash script with it's includes

Is there a way to view/show/print the source code of bash script with it's includes (sources)? Ex: sub.sh file function showMe(){ echo "INCLUDE" } main.sh file #!/bin/bash ...
3
votes
1answer
22 views

Use autocd and CDPATH together in a bash?

In a bash, is there a way to combine autocd and CDPATH, that is, to go to a subdirectory of a CDPATH element without typing cd before the dir name? For example, if i have these directories: ~ ...
-3
votes
0answers
19 views

bash script to display,add and delete data in a txt file(txt file is created seperately) [closed]

A script through which we can add,delete,display data(s) of a txt file created separately. The use should be like ./MY_SCRIPT -add [ID] -delete[ID] etc.
2
votes
2answers
121 views

Execute only if it is a bash function

I'm looking for something similar to Bash's built-in command that will only run something if it is a function. So currently I have an insecure way of doing: # Go through arguments in order for i in ...
2
votes
2answers
34 views

Change PS1 color when connected to other host via SSH

I'm trying to change PS1 look based on what host I'm connected in using SSH. My current PS1: PS1='\[\e[1;32m\]\u@\h\[\e[1;34m\] \w\[\e[1;31m\]$(__git_ps1)\[\e[1;0;37m\] \$\[\e[0m\] ' For host host1 ...
1
vote
2answers
102 views

Execute CURL command only once in script?

To explain a little, I am currently monitoring a folder for any changes and when changes are detected it simply uploads the detected files to my server via rsync. This is working without any issues : ...
5
votes
4answers
26 views

Renaming: How to attach a word or rename multiple files [duplicate]

I have multiple files in my directory. for example: eventDataLog.txt.2015-04-23-22 eventDataLog.txt.2015-04-23-23 eventDataLog.txt.2015-04-24-01 eventDataLog.txt.2015-04-24-02 ...
3
votes
1answer
47 views

Stat working in Bash 4.3 but not in Bash 3.2?

I'm using stat and for some reason it works on one my of my servers running the newer version of bash but not on the older version. Of course the errors are really generic, but they're coming from the ...
0
votes
0answers
20 views

Why rsyslog leaves the last file in spool directory

Suppose I am using a rsyslog remote server (R1) & have a client box (C1). C1 is configured to sync up and use R1 for logging (over port 514; TCP) The spool directory is '/var/log/rsyslog'. Now, ...
15
votes
5answers
1k views

How can the standard input of one program be passed as an arg to another?

Let's say a program exists, which takes two arguments; input file and output file. What if I don't wish to save this output file to disk, but rather pass it straight to stdin of another program. Is ...
1
vote
2answers
84 views

How to while read line with a pipe

I am currently trying read a csv file with BASH. The 10th [$f10] value of the csv file must be greater then 0 for a given machine class and machine ID [m_class] and [m_id] (these are user defined) . ...
1
vote
1answer
35 views

Copy array of multiple files with globbed extensions, in bash 3.2

I've found bits and pieces of each of the things I want to do across the Web, but nothing exactly fits my use case. I'm trying to write a script that copies multiple specific files to a directory on ...
2
votes
2answers
103 views

Redirect output of less utility to a file

Here is what I did less -N file1 > file2 what I want is writting file1 into file2 with line-numbers option. But I failed with that. Any suggestion to do that? Why I failed to do it? Thanks.
2
votes
1answer
104 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 ...
2
votes
3answers
72 views

Show only current and parent directory in bash prompt

I'm new to bash and would like my prompt to show something that in tcsh was trivial, yet after a good google search I still cannot do. I would like my prompt to include only the current and parent ...
0
votes
1answer
44 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
71 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 ...
2
votes
2answers
46 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 ...
1
vote
1answer
45 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 ...
3
votes
2answers
89 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 \ ...
-1
votes
1answer
27 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, ...
2
votes
1answer
71 views

Unable to get back to bash prompt after strange command

I was messing about with different wildcards and ran the following command: ls testdir/!(*/) after which I was completely unable to get back to the bash prompt. None of ^C, ^D, or even ^Z worked: ...
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> ...
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 ...
0
votes
1answer
61 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 ...
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 ...
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 ...
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 ...
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 ...