Questions tagged [bash]

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. For shell scripts with errors/syntax errors, please check them with the shellcheck program (or in the web shellcheck server at https://shellcheck.net) before posting here.

3,022 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
18 votes
1 answer
3k views

zsh can't input to terminal when piping stdin and stdout with variable command that has tty output

System info: macOS Sierra 10.12.6 zsh 5.4.2 (x86_64-apple-darwin16.7.0) GNU bash, version 4.4.12(1)-release (x86_64-apple-darwin16.3.0) Scroll to the EXAMPLES at the bottom if you just want to dig ...
dosentmatter's user avatar
7 votes
0 answers
232 views

Bash script containing sudo - unreliable background resume (bg)

I have the following simple bash script (called test.sh), that shows disk usage in the root dir. sudo is needed to list all directories (and I'm not asked for sudo password). #!/bin/bash sudo du -h --...
Artur Meinild's user avatar
7 votes
1 answer
2k views

Moving cursor to end of line when using history-search-backward

I recently added the following lines to my .inputrc: "\e[A": history-search-backward "\e[B": history-search-forward However, I noticed when using this that my cursor does not jump ...
John Howard's user avatar
6 votes
0 answers
1k views

Equivalent of PSReadLine for bash

For my Windows Terminal using Powershell I have the plugin PSReadline which gives me some pretty handy features. For instance a navigatable list view of my history when I start typing. So if I type cd ...
PalBo's user avatar
  • 161
6 votes
2 answers
2k views

Sending SIGINT to process groups sometimes gets ignored

I start a process group from bash. Then I send SIGINT to the entire process group. Sometimes the SIGINT kills the processes, sometimes does not. Why does SIGINT sometimes gets ignored ? I see ...
Hakan Baba's user avatar
6 votes
1 answer
2k views

Logging the output of remote commands on multiple ssh servers without delay

I've written a simple bash script that ssh's into 3 hosts (2 remote, 1 my own for testing) and runs a long running gui program that outputs text to the terminal that I'd like to log. #!/bin/bash ssh ...
user67081's user avatar
  • 161
6 votes
1 answer
1k 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.
Hans Ginzel's user avatar
5 votes
1 answer
185 views

Why does bash print exit even when it does not exit - is this a bug?

exit with zero or one numeric argument like exit or exit 42 print "exit" and exit the shell. exit with an invalid argument like exit hello prints an error message, prints "exit" ...
Sophia Koulen's user avatar
5 votes
0 answers
944 views

Kernel module remove not permitted for some sudo users

I use a sudoers file, which (besides other items) contains following lines: homebridge ALL=(ALL) NOPASSWD: /sbin/modprobe -r bcm2835-v4l2, /sbin/modprobe bcm2835-v4l2, /sbin/reboot %sudo ...
Erik Theoboldt's user avatar
5 votes
0 answers
958 views

Merge stdout and stderr, and create copies of each separately

My goal is best explained by example. To start, here's a function that will produce sample output, on both stdout and stderr: output() { printf '%s\n' 1 2 printf '%s\n' errA errB 1>&2 ...
Jonah's user avatar
  • 1,049
5 votes
2 answers
2k views

How to stop marking while in tmux copy-mode?

I want to mark and copy text, and then stay in copy-mode with the marker off, permitting me to move up/down without marking new text (see below). But after marking text and pressing space or y to ...
Shuzheng's user avatar
  • 4,073
5 votes
0 answers
278 views

Bash completion own compgen prefix

I have a simple bash completion script that essentially invokes my (non-bash) program and set its output to COMREPLY, i.e. COMPREPLY=( $(my-program -- "${COMP_WORDS[@]}") ) Some of the options ...
Limon's user avatar
  • 161
5 votes
1 answer
858 views

How can I properly use an American flag emoji in my bash prompt?

I want to use an American flag emoji in my bash prompt (i.e. PS1 environment variable). However, the American flag emoji causes the terminal cursor to offset an extra character to the right. 🇺🇸 is ...
Andrew Kirna's user avatar
5 votes
1 answer
497 views

Pasting into terminal including comments issue

This is somehow a follow-up to my last question: Pasting multiple commands into terminal stops at user input Pasting the following to the terminal works as expected: ( echo test1 # some comment echo ...
pLumo's user avatar
  • 22.3k
5 votes
1 answer
2k views

TOR hidden service not always accessible through cURL. Takes multiple tries

When I try to access a hidden service on TOR using cURL, for some reason I'm not getting access to the site 100% of the time. Many times it returns "curl: (7) Can't complete SOCKS5 connection to 0.0.0....
I like to code's user avatar
5 votes
1 answer
634 views

Assign both menu-complete and dynamic-complete-history to TAB

Is there a way for me to assign both menu-complete and dynamic-complete-history to Tab (or one to Tab and the other to Tab-Tab) in .inputrc? I'm thinking there might be a way to setup a function and ...
victorbrca's user avatar
5 votes
1 answer
256 views

git report moved lines

I want to track the number of additions and deletions that exclude moved lines. So if a commit has 10 additions, 5 deletions, and 3 moved lines, then I have 7 additions, 2 deletions excluding moved ...
rjturn's user avatar
  • 191
4 votes
0 answers
42 views

Name of background job started from EXIT trap is wrong

The following script: #!/bin/bash set -m atexit() { sleep 1 & jobs } trap atexit EXIT echo Hello world Produces this output: $ bash ./foo.sh Hello world [1]+ Running ...
Tavian Barnes's user avatar
4 votes
1 answer
3k views

E: The repository 'http://security.ubuntu.com/ubuntu impish-security Release' does not have a Release file

when I try to command : sudo apt update this error was shown: E: The repository 'http://security.ubuntu.com/ubuntu impish-security Release' does not have a Release file. N: Updating from such a ...
Javad Kefayati's user avatar
4 votes
1 answer
335 views

What is the purpose of a pipe after stdout redirect?

I was reading the documentation for Kaniko and saw a shell redirect-then-pipe construct that I haven't seen before: echo -e 'FROM alpine \nRUN echo "created from standard input"' > ...
Andy Brown's user avatar
4 votes
0 answers
339 views

How to cancel edit-and-execute-command?

Is there a way to not execute a command, once I have pressed Ctrl+X Ctrl+E? (edit-and-execute-command) Ideally like in git: If I save the file (like :wq in vim), it gets executed, but if I close the ...
Thomas Ahle's user avatar
4 votes
0 answers
345 views

Configuration or command to for case insensitive bash history search

Bash provides the interactive commands forward-search-history and reverse-search-history typically bound to the keys CTRL-s and CTRL-r respectively. Are there case-insentive equivalents or is there a ...
Harald's user avatar
  • 826
4 votes
0 answers
185 views

Why does bash $LINENO change inside an inner block in a function?

I'm trying to debug auto completion script located in /usr/share/bash-completion/bash_completion (bash completion package on every distro) I did export PS4='+'$'\t''$LINENO'$'\t # \t for proper ...
Alireza Mohamadi's user avatar
4 votes
0 answers
347 views

bash [-+]O shopt_name doesn't work the way it's supposed to as per by the manual

The bash manual says: " [-+]O [shopt_option] shopt_option is one of the shell options accepted by the shopt builtin (see SHELL BUILTIN COMMANDS below). If ...
The_Weeping_One's user avatar
4 votes
0 answers
447 views

bash + how to avoiding duplicate entries in authorized_keys (ssh) in bash

Popular methods of adding an ssh public key to a remote host’s authorized_keys file include using the ssh-copy-id command, and using bash operators such as >> to append to the file. An issue ...
user avatar
4 votes
0 answers
492 views

HISTCONTROL - When is erasedups executed?

I know that ignorespace and ignoredups work in real time and prevent entries going into the buffer, but when does erasedups come into play? Is it when the buffer is written/appended, is it when the ...
Chris's user avatar
  • 305
4 votes
0 answers
326 views

Is there a command like `time` that monitors the network traffic of commands?

I can use the time command to measure the time some command takes: time node -e "" node -e "" 0.06s user 0.01s system 92% cpu 0.076 total Is there a similar way to measure a ...
HappyFace's user avatar
  • 1,493
4 votes
0 answers
179 views

On MacOS, what character does `Esc+` or `+Esc` correspond to in Bash, when using iTerm2 terminal?

I've read that mapping Left Option key to Esc+ should fix many of the issues users of Bash, on MacOS, have with GNU Readline key-bindings. However, I've never encountered Esc+ or +Esc before, so does ...
Shuzheng's user avatar
  • 4,073
4 votes
0 answers
722 views

What are exactly shells levels?

My understanding of shell levels and sub-shell was that: Sub-shells are forks (but not execs) of the shell process created by ( ... ) constructs. $SHLVL counts shell execs. $BASH_SUBSHELL counts sub-...
Louis Blanchard's user avatar
4 votes
0 answers
2k views

chmod always gives "illegal option" error

No matter what chmod command I run, I am always getting chmod: illegal option -- - usage: chmod [-fhv] [-R [-H | -L | -P]] [-a | +a | =a [i][# [ n]]] mode|entry file ... chmod [-fhv] [-R [-H | -...
masterpiece's user avatar
4 votes
0 answers
364 views

Colorize the PS4 prompt?

With the option set -x, each command is echoed to STDERR before execution, prefixed by the expanded $PS4, with the first character being repeated according to the call stack depth. I want the output ...
kdb's user avatar
  • 199
4 votes
1 answer
1k views

Adding "sudo" commands to the bash history of the *target* user

Something that's bothered me for many years is that if I want to search my shell history for commands which were run as root, I have to check two different locations: I have to check /root/....
Rag's user avatar
  • 146
4 votes
1 answer
746 views

Nested command substitution does not stop a script on a failure even if -e and shopt -s inherit_errexit are set

Suppose you have a following script sandbox.sh. (This looks similar to Command substitution inside a function does not stop the script on a failure even if -e is set, but I believe a bit different ...
Hiroshi_U's user avatar
  • 167
4 votes
0 answers
991 views

How to show rsync progress when running as systemd service

I have a bash script sync_nodes.sh that I want to manage with a systemd unit sync_nodes.service. I want the progress of of the rsync command to show up in my logs. When I run the command ...
mbigras's user avatar
  • 2,928
4 votes
0 answers
745 views

How to keep screen running after exiting the command that runs in it?

I have the task to start a detached screen session (e.g. when the system reboots) and then to be able to connect to it and interrupt/kill the running process without the screen to terminate. ...
Gabriel Petrovay's user avatar
4 votes
3 answers
4k views

How to execute script on remote server after loggin in through ssh

I'm managing a bunch of servers so I frequently have to ssh into them. I'd like to automatically run a basic custom script on whatever remote server after logging in. Say to set up some aliases, ...
arod's user avatar
  • 771
4 votes
0 answers
499 views

Is it possible to fork the current pane in tmux and put it in a new pane?

Often I have set up some temporary environment variables/modules and I would like them to persist as I create a split in Tmux. Is it possible to fork the current running program (i.e. bash) and put ...
Derek 朕會功夫's user avatar
4 votes
0 answers
5k views

Bash script calls python script that wants interactively input ( not only arguments )

I have a bash script bash.sh that looks like this: #!/usr/bin/env bash /usr/local/sbin/pythonScript.py firstArgument secondArgument If I call the pythonScript.py from my terminal with the two ...
Viktor Carlson's user avatar
4 votes
0 answers
3k views

Will a child process be in a different process group than the parent process?

I always thought that a child process will be in the same process group as the parent process. But I have read the following from here: if you run some_app from the shell, the shell creates a new ...
user259392's user avatar
4 votes
0 answers
1k views

How to bind to ctrl+x in bash?

I appear to be using GNU bash, version 4.4.12, though it's possible my organization has modified it from HEAD. I'm trying to bind ctrl+x: $ bind -x '"\C-t": "echo testing"' <I press ctrl+t> ...
Dave Johnson's user avatar
4 votes
1 answer
411 views

is it possible to colors the prompt for (reverse-i-search) context menu?

I am using fedora 25 but I think this is a general behavior on unix system. When I ctrl+r in a command-line environment I can start to type in and anything I type will get to be matched backward in ...
vdegenne's user avatar
  • 1,696
4 votes
0 answers
1k views

How to set the default color of output / things typed in Bash

When I am typing or viewing text on my terminal, the color is white. Any command after I type my prompt is white, and the default output (stdout) is white. I looked and my terminal emulator does not ...
Startec's user avatar
  • 1,839
4 votes
0 answers
1k views

Coloring terminal commands ("syntax highligting" on command line)

I do know I can color my prompt using escape sequences in the PS1 variable. Now, I would like to know if there is a way to put some color on the bash commands I often use, on the command line itself. ...
Matheus Ferronato's user avatar
4 votes
0 answers
288 views

How to explicitly set the tabname of a new gnome-terminal?

I want to explicity rename a tab in gnome-terminal on startup of the tab. I don't want to use gnome-terminal --title flag as that gets reset by my systems bashrc file after whatever else is supposed ...
Prodnegel's user avatar
  • 141
4 votes
2 answers
457 views

bash/cygwin broken after installing rtool?

Usually I can solve problems on my own (and Google). But recently I am baffled by this strange hiccup. Background: I use a chain of scripts for file-processing (in Windows, under Cygwin. Scripts ...
Yifeng Mu's user avatar
  • 969
4 votes
0 answers
1k views

Bash command history stops working after starting new tmux session

My bash command history stops working after starting a new tmux session. No previous commands when typing up, down, reverse search, no output from running history. I've confirmed that this happens ...
Brian Duncan's user avatar
4 votes
0 answers
613 views

Replacing a running binary on read-only file system

I have a simple updater bash script, which replaces files by removing the incident old files and copying new files from an archive to the running embedded target root file system. This way, the script ...
yman's user avatar
  • 181
4 votes
1 answer
436 views

Bash prompt - backspace deletes right aligned text (possible to stop?)

I have a really annoying problem. I have followed all of the protocol for making a bash PS1. I know about surrounding non-printable characters with \[ and \] or \001 and \002; however, I have a ...
Dylan's user avatar
  • 435
4 votes
0 answers
344 views

Bash command not found due to stray garbage characters

What is the cause of this behavior? $ cd ../ $ bash: $'\210\210cd': command not found This happens sometimes (rarely) when I enter a command, there is no visible character preceding the cd, still it ...
AttributedTensorField's user avatar
4 votes
2 answers
524 views

Context-sensitive bash completion changes wildcard behavior

Somewhere along the way I've fallen into the habit of hitting tab twice after using a wildcard in commands like mv or rm, which by default causes bash to show the list of files that would match the ...
Drew's user avatar
  • 396

1
2 3 4 5
61