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
1answer
32 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
133 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
61 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 ...
1
vote
2answers
34 views

How to start a new shell, pass it new environment variables, and work there until exit?

I need a special shell environment set up to interact with an commercial application that we have purchased. The environment is queried "on the fly" from the application. So I've attempted to start ...
0
votes
1answer
16 views

exiv2 piped to grep - random inconsistent behavior

For a bunch of jpg photos, I have this (simplified) script to be able to extract the original date when the photo was taken (if different of 0000:00:00, not relevant for this case) for f in *.jpg; do ...
0
votes
2answers
33 views

Remove string that has special characters

I have a file called test similar to the following: hello my name <h6>test morning</h6> is bob I know I would use: sed -i -- 's/name//g' test To remove name from the file, but how do ...
23
votes
1answer
846 views

What is the bash '<(file contents)' syntax called?

This answer on Security StackExchange uses an interesting bash syntax to generate a file in-line: openssl req -new -x509 -nodes -newkey ec:<(openssl ecparam -name secp384r1) -keyout cert.key -out ...
12
votes
1answer
121 views

[[ and case equivalency in bash

Does if [[ "$1" = pattern ]]; then hook fi always behave the same as case "$1" in pattern) hook;; esac or are there any gotchas?
1
vote
0answers
26 views

Make Bash's vi-mode default to “normal” Vi mode (not “insert”), and place cursor at start of line, mimicking KornShell

I'm trying to get Bash to mimic the behaviour of KornShell93 (ksh) when the shells are in Vi command line editing mode. KornShell defaults to "Vi normal mode" (a.k.a. "command" mode) and it also ...
0
votes
2answers
44 views

aliasing command which takes argument with using pipe

I would like to create an alias in my ~/.bash_profile that will: Take two arguments $1 $2 Pass these to diff Pipe the output to less I have not found any solutions on Stack that do what I need, ...
-3
votes
1answer
37 views

Check the frequncy of a character's consecutive occurences [closed]

I need a way (in Bash) to check the consecutive occurrences of a character, however it also needs to be capable of having a limit of occurrences before it is considered to be a second variable, in ...
1
vote
2answers
62 views

Executing commands consequtively on multiple folders

I have parent folder "parent". Inside this folder I have subfolders, and a file named "names.txt". this file includes the names of these subfolders as follow: Parent_folder folder1 folder2 folder3 ...
12
votes
1answer
236 views

See the expansion of Bash variables for debugging?

Is there any tools/tricks available for expanding variables to make bash code easier to read? For example it would convert the following: DIR=/var/tmp FILE=${DIR}/file SCRIPT_ROOT=/opt/root TOOL=${...
0
votes
1answer
49 views

Non-Interactive input

I am trying to run a bash script which downloads and runs another script. The second script contains questions that must be answered by input. I have already attempted to use expect but it fails ...
0
votes
1answer
20 views

How to use bash variables inside make

I thought that make interprets the rule's set of commands literally, passing them to the sub-shell. But this doesn't seem to work in this case: default: loop echo $$RANDOM This prints echo ...
1
vote
1answer
39 views

Pipe demon output to a function

I'm receiving a MQTT message with mosquitto_sub and I want to redirect the output (two strings) to a function. CLIENT: mosquitto_pub -d -t hello/world/ -m "Alessio,base64" On the server I have a ...
2
votes
2answers
68 views

bash:Syntax near unexpected error '(' [closed]

I am following a tutorial in computational microbiology: William Lindstrom, Garrett M. Morris, Christoph Weber, and Ruth Huey (2008-01-29). Using AutoDock 4 for Virtual Screening. Scripps Research ...
4
votes
4answers
424 views

How to obtain grep exit status into a variable

I started learning Bash a couple of days ago. I'm trying to obtain an exit status of grep expression into a variable like this: check=grep -ci 'text' file.sh and the output that I got is No ...
2
votes
2answers
33 views

How to specify protocol prefix containing “:” to bash-completion function _known_hosts_real

I am attempting to use bash-completion for URLs of the form "proto://host". Without the ":", I see expected behavior, with the ":" present, the URL comes out "faulty". Bash completion has a function ...
1
vote
3answers
74 views

Read lines from a file into a variable

I'm trying to automate a large process to save time and effort and I'm probably making it way harder than it needs to be. What I'm doing so far is: #!/bin/bash LISTFILE="/tmp/filename" for FILE in $...
5
votes
2answers
66 views

Is getopts always available for Bash?

Can I use getopts for parsing command-line arguments in my bash scripts(not sh) without worrying about another depedency?
0
votes
1answer
70 views

Writing output of command to variable [closed]

I would like to put the output of a command into a variable. As far as I know, you have to use either of these: variable=$(command) variable=`command` The following should work from my point of ...
1
vote
0answers
31 views

evaluating dual blocking commands in a bash condition statement

I am attempting to write a loop that refreshes a terminal either 1. when the file(s) have been modified, or 2. When user input is detected second interval. I know how to do one at a time, like so: ...
1
vote
2answers
42 views

Compute Sum Of Date

A third party script we use pulls information based on the number of minutes a certain job runs for. I need to enter this input in the script. E.g Here is an example export etool_start=`date +"...
11
votes
4answers
370 views

When is {a,b,c} expanded in bash, when is it not?

A bash script that contains for i in {a,b}-{1,2}; do echo $i; done prints a-1 a-2 b-1 b-2 when executed. This is what I expected - as the {a,b} construct is expanded. However, when (another) ...
0
votes
1answer
22 views

Bash - How can I make selection menu of zip files based on how many zip files in a directory?

I am doing a theming tool script. I want to make a selection menu of zip files (zip file contain theme) in a directory, then users will choose a zip file they want to install Example: in /theme/...
2
votes
0answers
52 views

Bash completion extra space when adding file directory

I have a script for extending bash-completion for certain commands. If I type command1 and do a tab, it should auto-complete with a file directory (and the files). It works fine expect for one ...
1
vote
1answer
36 views

Colour-coordinate symlinks/softlinks based on where they refer to

Is there any way to colour coordinate symlinks/softlinks based on where they're linked, or maybe by who they 'belong' to (similarly to colouring the output of ls for example)? To give you an example ...
1
vote
0answers
26 views

Should I quote variable when passing to command? [duplicate]

I always do this when passing variable to command mkdir -p "$dir_to_make" are those quotes needed? I tried to google but didn't find much. I always write them, just interested if they are necessary....
28
votes
3answers
4k views

Bash - How can I make “Press any key to continue”

I'm making a script to install my theme, after it finished installing it will appear the changelog and there will be "Press any key to continue" so that after users read the changelog then press any ...
4
votes
3answers
402 views

How can I determine the OS within .bash_profile? [duplicate]

On my main machine, a MacBook Pro, I have a .bash_profile file that I'd like to use unaltered on my Dreamhost linux machine. However, there's a few lines that are only applicable to macOS, such as ...
0
votes
1answer
39 views

Why do these commands produce different outputs?

I am trying to get the linux timestamp from a row of text. I can use the cut command to grab the string > echo '"tester_row_____",0,"2016-07-04T01:42:28Z","2016-07-04T02:00:58Z"' | cut -c 22-41 ...
2
votes
1answer
27 views

How to automatically load tmux at login, but not if already inside tmux?

I'm a linux noob and recently started using tmux. I found I can attach-or-create a tmux session by using: tmux new-session -A -s main I was hoping to put this into .profile so that I automatically ...
2
votes
2answers
44 views

sed to print pattern that spans across lines

I'm learning sed and I'm currently stuck with the following problem: I want to extract the lines found between ^C's from the following output: banner exec ^C This is the banner ^C banner motd ^C ...
5
votes
3answers
294 views

for loop glob mishaps

I am trying to set up a script that will loop over a set of directories, and do one thing when it finds .jpg files, and another when it finds .nef files. The problem is, if a directory does not have ....
1
vote
1answer
86 views

Bash - How to make each menu selections in 1 line instead of multiple selections in 1 line

Im making a tool script for my theme has 6 options: 1) Check theme update 2) Reinstall theme 3) Install font 4) Install wallpaper 5) Check tool update 6) Quit Here is the code clear echo "===========...
0
votes
4answers
61 views

Find folders that begin with the same string

I have more than 1000 subdirectories in a folder. Some of them begin with the same string and I want to find all directories where the first 5 characters of their name are also the first 5 of another ...
0
votes
0answers
41 views

Is there a bash IDE like there is for R? [duplicate]

Just wondering if there is a bash IDE like there is for R, meaning you type commands in a text area and send lines, blocks or selection to bash just like you would do with let's say Rstudio. My goal ...
0
votes
2answers
69 views

bash - How can I re-display selection menu after a selection is chosen and performed

I am a beginner to script. I am making a tool script for my theme with 2 functions: Check for update, reinstall theme So here is the code for selection menu: PS3='Choose an option: ' options=("Check ...
2
votes
1answer
31 views

Clarification for Bash documentation on disown builtin option -h

According to the documentation: To prevent the shell from sending the SIGHUP signal to a particular job, it should be removed from the jobs table with the disown builtin or marked to not ...
1
vote
0answers
32 views

Any caveats to using bash disown from a shell script as an alternative to screen?

I have a process which starts and outputs to a log file. The script which starts it launches it in a GNU screen and then follows the log with tail. The process will immediately begin writing to the ...
1
vote
2answers
63 views

How to print all subsets of a set? [duplicate]

How can I print all subsets of a set using bash script. like : {} , {1} ,‌{2} ,{1,2} for A={1,2} this is what I have already write but I always thinks there must be a better way also my script just ...
0
votes
0answers
31 views

command substitution within c style for loop in Zsh

I have a function printing a number myFunc() { echo 11 } Now I want to use the number in expression in c style for-loop: for (( i=1; i<=$(myFunc); i++ )); do echo "$i" done Zsh gave ...
1
vote
1answer
43 views

bash for loop variable not changing

I am iterating over indexes which are used to create data file id's. When I create the file name (data_file) and echo it, it prints properly, but when I try to sed that variable into the desired files ...