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

1
vote
2answers
43 views

How to run a bash script from a sh(dash) script?

I have a sh (shebang #!/bin/sh) script (sh.sh) which invokes a bash (shebang #!/bin/bash) sub-script: . "some-path/bash.sh" In the bash script I have a declaration of an associative array: declare -...
3
votes
3answers
114 views

How to read a properties file into an associative array?

I'd like to read the properties in a properties file into an associative array. How can I do it? Specifics on what to parse: hash and equal signs. Everything else is a bonus. Properties file content ...
1
vote
1answer
37 views

Segmentation fault when calling a recursive bash function

I have hundreds of multiple folders which contains thousands of zip files which contain nested within the zip files like show on three below start tree structure 012016/ ├── 2016-01 │   └── 2016-01 │ ...
1
vote
0answers
25 views

Completion with wildcards in directory names in bash

I can do: $ cd sources/ar #[TAB] here would complete word 'ar' to 'art' I can do $ cd */art #[enter] here would bring me to sources/art I can do $ cd */art #[TAB] that would expand */art to ...
3
votes
1answer
40 views

Ordered by insertion Map in bash

Is there an ordered (by insertion) map in bash? I know there's an associative array data structure in bash, but when iterating over it, the order of the elements is not by insertion. Example below. ...
0
votes
0answers
28 views

SUID bit does not work even though I put the binary on a non-nosuid mount [duplicate]

I am trying to test out how suid would work. I have this for my binary: #include <stdlib.h> #include <stdio.h> int main(int argc, char *argv[]){ system("/bin/sh -c whoami"); ...
3
votes
3answers
151 views

Could not execute a Bash Script if / while

I would like if someone points out mistakes in my script. The source where I'm learning from is so buggy that's why it's confusing me. PURPOSE OF THIS SCRIPT: It will count the numbers from ...
1
vote
1answer
36 views

Something like $CDPATH that works for all bash commands

I'm trying to figure out if there's a way I can get $CDPATH working for every command-line tool. At the moment, I have a directory in my homedir that's called src/ which contains all of my projects. ...
1
vote
2answers
41 views

Syntax Error near Unexpected Token in a bash function definition [closed]

Forgive me; I'm pretty new to bash files and the like. Here is a copy of my .bashrc: alias k='kate 2>/dev/null 1>&2 & disown' function kk {kate 2>/dev/null 1>&2 & disown}...
5
votes
2answers
136 views

Array Expansion

I am having unexpected results in expanding an array. I am hoping someone can shed some light on why I am seeing what I am seeing. I am trying to populate an array using fdisk -l to fill it and only ...
3
votes
0answers
36 views

SIGINT is not cleaned up in “${FUNCNAME[@]}”

Take the following script, interrupted by keyboard input ^C as shown: $ function a() { echo "Performing"; sleep 10; echo "Performed"; } $ a Performing ^C $ echo "${FUNCNAME[@]}" a source If we ...
14
votes
2answers
1k views

How do programs output to elsewhere than STDOUT/STDERR? How to avoid it?

Apparently I don't know all the output destinations that are available for use. I know about stdout(&1) and stderr (&2). However, after redirecting both descriptors, I sometimes still get some ...
0
votes
1answer
32 views

Dispatching files to directories using name pattern matching

Consider: $ ls about-bar about-bar.pdf about-foo about-fou.pdf $ for f in *about-*.pdf; do mv "$f" "$(echo $f | sed -E 's:(about-.*).pdf:\1:')";done $ find . . ./about-bar ./about-bar/about-bar....
1
vote
1answer
52 views

How to get second to last parameter of previous command in bash?

I can use Esc+. to get the last parameter of the previous command, but is there an equally convenient short-cut to get the second to last parameter?
0
votes
1answer
33 views

HH:MM:SS (with AM/PM) 12 Hour Timestamp for Bash Prompt

I'm trying to add a timestamp to the beginning of my bash prompt in the format of a 12 hour HH:MM:SS AM/AM clock, and as of now, I've had no luck. Here's a couple things I've tried. I've tried date +%...
2
votes
1answer
32 views

Terminal prompt is being written over top of [duplicate]

I should preface this by saying this terminal session is via ssh from Windows PuTTY to Linux OpenSSH. I'm not sure if this matters, but I figured I should say it anyways. Currently, when I write more ...
3
votes
2answers
56 views

renaming mp3 files starting with “-”

I've extracted songs from my ipod, but when doing so, every song was renamed "- [original name of the song]" . I wanted to write a bash script that would remove that first "-" because there are maybe ...
0
votes
1answer
31 views

Variable Capture and For-Loop Arithmetic

My input files are a single column with variable length of rows. My code is supposed to count those rows, and print a specified number. The problem I'm having, is if the number of rows captured in the ...
4
votes
2answers
66 views

What's the difference between “>&1” and “>/proc/self/fd/1” redirection?

I'm working on some script that being run by rc.local at startup, and I noticed that output redirection works quite strange. If I write something like echo "foo" >&1, it ends up in syslog, and ...
6
votes
1answer
96 views

Cannot exec /bin/false: no such file or directory

I'm trying to open GNU Screen with the following command on my Mac OS: host:~ user$ screen The screen terminal opens but quickly dies with the error message: Cannot exec /bin/false: no such ...
0
votes
0answers
25 views

alias defined in modulefile does not work in launched shell [duplicate]

I am trying to get aliases working on my company's number crunching machine, which uses the bash shell on CentOS 7. For software management, we use GNU modules. Some case set-ups for certain ...
0
votes
1answer
29 views

HISTFILE env var unset within programs. Can I access it in any way? [duplicate]

When I try to access the "HISTFILE" env var within a program, it isn't there $ echo $HISTFILE /Users/drewgross/.bash_history $ python Python 2.7.10 (default, Oct 23 2015, 19:19:21) [GCC 4.2.1 ...
0
votes
2answers
33 views

How to modify output on a bash terminal for all outputs

I would like to be able to permanently edit my setup (I am running ubuntu) so that every time the terminal outputs something it adds something to the output. An example of this would be to add a line ...
2
votes
1answer
84 views

Move all files into subdirectories named after beginning of file name

I have a directory that contains quite a lot of files with names made up of 8 random letters, numbers, _ and -, e.g.: 0dckGYH5.jpg 32Pz5-WQ.png 32_17pxH.png Hsf4BQW9.jpg xh-fa3Nu.gif zYtBEaKA.png ... ...
1
vote
5answers
93 views

Killing a named process older than X minutes? (no killall -o)

Okay, first post! So I have this situation where I need to check for a process older than 5 minutes by a particular process name. The problem is that the system in question is a customized version of ...
0
votes
1answer
46 views

`source …/settings.csh` not working from `sh ./test.sh`

I want to source Xilinx ise setiin64.csh file with the source command. I have source /home/xilinx/ise_14.5/14.5/ISE_DS/settings64.csh in another file, test.sh. So I want to run only test.sh file ...
0
votes
2answers
50 views

Adding find contents to array

I've currently got a script that generates R commands based on the output of find #!/bin/bash PATHX="/path/to/my/files" find "${PATHX}" -maxdepth 1 -type f -name "*.csv" | while read d; do FN=$(echo -...
4
votes
1answer
470 views

which bash is executing?

I think I have configured bash as shell, but why is this happening? My shell is bash: # ls -al `which sh` lrwxrwxrwx 1 root root 4 Jul 12 03:25 /bin/sh -> bash Error executing a script with ...
3
votes
1answer
88 views

Can I get bash to ignore leading `:` when it's present?

Often, if I'm working in bash (on macOS), I'm also working in (Mac)Vim, switching between the two. A common mistake I make after switching from Vim to Terminal is to include a leading colon before the ...
2
votes
2answers
49 views

Bash function comments before or inside the function [closed]

Does the Bash language have a standard that dictates whether comments about the function should precede the function or be placed inside of it. I have seen scripts written both ways. # Comment ...
2
votes
4answers
193 views

running commands consecutively in a bash [duplicate]

The following bash permits of running the commands 1,2,3 in all the folders that has names included in the file "list.txt" #!/bin/bash cat list.txt | while read i do command1 & command2 & ...
0
votes
1answer
34 views

read 1 or several lines in bash - make it work when pasting (in addition to typing manually)

I read multiple answers with varying complexities. Most are working well when the input is typed manually. For example: http://stackoverflow.com/a/20913871/1841533 . Here is my sample code, very ...
1
vote
1answer
35 views

`Interact` not working as expected in bash/expect scripting

In order to provision an embedded device (i.e. writing images to flash) a series of very well known commands have to be entered during the boot stage. The algorithm is something like: Capture a ...
3
votes
1answer
35 views

Spurious @ symbol at start of bash prompt in Debian Jessie

As of late, and without my deliberately doing anything to make it happen, my Bash prompt has an at sign (i.e. @) prepended to it. This did not previously happen. Nor can I see anything in my ~/.bashrc ...
2
votes
2answers
55 views

shopt -s extglob not working as expected

I am trying to recursively change file permissions in a wordpress installation affecting everything below the public_html document root folder, excluding certain folders. I have set extglob on with ...
3
votes
1answer
25 views

Loop over a string in zsh and Bash

I would like to convert this Bash loop: x="one two three" for i in ${x} do echo ${i} done in such a way to work with both Bash and zsh This solution works: x=( one two three ) for i in ${x[...
1
vote
1answer
26 views

Event dispatcher in bash (Ubuntu Gnu/Linux) [duplicate]

Are there any methods or bash tools that can observe some events (such as creating a folder) and then do another actions?
6
votes
1answer
60 views

Displaying usage comments in functions intended to be used interactively

I have a number of functions defined in my .bashrc, intented to be used interactively in a terminal. I generally preceded them with a comment describing its intended usage: # Usage: foo [bar] # Foo'...
0
votes
1answer
35 views

Why does my terminal say I'm running -bash (with a leading dash) and not bash?

I have recently started learning UNIX for a week or so and I've played around with the bash_profile and bashrc files to add in some basic preferences. But today, I couldn't execute several terminal ...
3
votes
2answers
77 views

Comparing Negative values in bash using arrays

I do have a interesting problem that I am trying to tackle but I am yet unable to do so. Let suppose that I have 2 arrays. Array One: 1 -2 3 -2 2 -4 Array Two: -2 -3 4 5 2 -5 I want to be able ...
6
votes
2answers
84 views

Read special keys in bash

I am playing with a script that, among other things, list a selection-list. As in:1) Item 1 # (highlighted) 2) Item 2 3) Item 3 # (selected) 4) Item 4 When user press down-...
1
vote
1answer
30 views

Autocomplete deletes last character from words sometimes

I have a custom command define that gets words definition from dictionary. I wanted to make an autocomplete script to complete the words I want to define using the list of words found in /usr/share/...
3
votes
1answer
39 views

how to set globstar for noninteractive shells

I would like to execute commands noninteractively on a remote server that use the ** globstar option. However, globstar is not set by default on the remote, and bash doesn't source any files in ...
-1
votes
1answer
34 views

cancel script execution and continue [closed]

I have a script which runs another script. myscript.sh #!/bin/bash .... cd /folder/ sh run.sh sh another_script ... the procedure: So , I start running myscript.sh , the script runs it's ...
1
vote
1answer
126 views

“-bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)”

Running a brand new Ubuntu 16.04 and a Debian 8 server. Trying to connect via ssh and getting the following strange terminal output. I refer to the rectangles with the numbers in it. The problem ...
0
votes
0answers
23 views

How to selectively disable auto-complete?

I've created a large number of utility scripts, that I use to make my work-life easier. All of those reside in my home directory, so that I can easily run them as ~/<script>. Being as clumsy as ...
1
vote
2answers
59 views

chown doesn't work through script

I have a script: #! /bin/bash sudo chown -R $USER:$USER /opt/Folder The chown doesn't seem to execute. If I just write the above line from terminal ,it runs fine though! I have read this but ...
5
votes
3answers
74 views

How to make a redirection loop

This one is mostly for academic reasons. ;-) Consider the following Bash statement: foo | bar This executes two processes, foo and bar, such that the standard-out of foo is connected to the ...
2
votes
2answers
35 views

Mouse click integration with SSH client, on command line, not just vim?

In vim, you can use the option :set mouse=a, and then (if your SSH client supports it) you will be able to simply click and the cursor will move, rather than having to use the arrow keys or whatnot. ...
0
votes
2answers
24 views

Bash scripting: Change standard error message for custom one

I have been trying to work on my own little backup script. I am running into an issue when I run my script and the rm command has nothing to do. I would still like to process the output (aka display ...