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.

2,142 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
13
votes
1answer
1k 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 ...
11
votes
1answer
2k views

Real GNOME Wayland session

I'm trying to test a "real" wayland gnome session. I know that not all applications can run on Wayland natively (for this we have XWayland) but at least I would like to have GTK+ applications to do so....
8
votes
0answers
116 views

Shell dropping every other character of input

I manage software on a bunch of RHEL 6.10 VMs, typically either as a service account or root using sudo -i. Periodically, my shell starts dropping every other character. For example, if I type cd /usr/...
7
votes
0answers
38 views

Why does watch not show anything on screen when invoked with timeout in an script?

When I run this script, it does not display the watch output on the screen, and does not timeout after 5s. § cat script.sh #!/bin/bash timeout 5s watch -n 1 ps This is what I see on the screen when I ...
6
votes
2answers
534 views

autocomplete filenames with underscores

What do I need to add to my ~/.bashrc so that if, for example, there is a file named name_separated_by_under_score, I can press n-s-b-u-s and then [TAB] and the shell will auto-complete the file name? ...
5
votes
0answers
195 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 ...
5
votes
1answer
117 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 ...
5
votes
1answer
762 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 ...
5
votes
1answer
943 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 ...
5
votes
1answer
373 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 ...
5
votes
0answers
4k views

“-bash: /root/.bashrc: Permission denied” when logging in

I have this server running Centos 7. Every time I log in (remotely or locally) with every user I get an error. If I log in as root I get -bash: /root/.bashrc: Permission denied If I log in as a ...
5
votes
1answer
534 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 ...
4
votes
0answers
40 views

Why does ZSH finish executing a function after exit was called from a trap?

Consider the following script: trap "echo TRAPPEDTERM >&2; exit" TERM termself () { kill -TERM $$ echo "Survived TERM!" } termself echo "Bye." Executed ...
4
votes
0answers
40 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 ...
4
votes
0answers
89 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-...
4
votes
0answers
71 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 ...
4
votes
1answer
362 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/....
4
votes
0answers
579 views

Turn on xtrace with environment variable

Bash has a sometimes-useful feature whereby if you turn on the "-x" option (I believe the symbolic name is xtrace), Bash outputs each line of script as it executes it. I know of two ways to enable ...
4
votes
0answers
61 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 ...
4
votes
0answers
462 views

how to avoid writing failed bash commands to bash_history

I'm looking for a nuanced history behavior I haven't seen anywhere. During a terminal session, I want every command, regardless of exit status, to be appended to the in-memory history. Upon exiting ...
4
votes
0answers
739 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> ...
4
votes
1answer
246 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 ...
4
votes
2answers
339 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 ...
4
votes
0answers
633 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 ...
4
votes
0answers
383 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 ...
4
votes
1answer
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....
4
votes
0answers
318 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 ...
4
votes
1answer
2k views

Automating sshfs not working

I want to mount a remote directory and I want to automate this. So I write below script which not working properly. #!/usr/bin/expect -f spawn sshfs vedams@192.168.5.109:/home/user /mnt/remote expect ...
4
votes
1answer
78 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 ...
4
votes
2answers
1k views

Bash shell launched by forkpty() spawns child processes that ignore SIGINT. Why and how do I ensure SIGINT is not ignored?

I have a C program that uses forkpty to execute a bash shell. I'm finding that the programs launched by this shell are launched with SIGINT ignored, so when I send a Ctrl-C to the shell they never ...
3
votes
0answers
25 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 ...
3
votes
0answers
66 views

How to pipe all output streams to another process?

Take the following Bash script 3-output-writer.sh: echo A >&1 echo B >&2 echo C >&3 Of course when ran as . 3-output-writer.sh it gets the error 3: Bad file descriptor, because ...
3
votes
0answers
53 views

How to refer to a command beginning with $?

Assume that the history list contains the command e='echo a b c' and then $e. How to refer to the command $e using the history expansion feature of bash?
3
votes
0answers
46 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 ...
3
votes
0answers
56 views

Why does CTRL-C work in one user account but not another?

I have a bash script which is supposed to run a command every X seconds, until the operator interrupts it. Like this: test.sh #!/bin/bash while true; do echo Doing a thing... sleep 3 & ...
3
votes
1answer
140 views

Get and set the script arguments from within a function in bash

Context: I have an old bash script with a big section parsing its arguments. It happens now that I need to call this section twice, so I plan to move it to a function to avoid code duplication. ...
3
votes
1answer
221 views

Why doesn't 'sudo -E' preserve the function environment variables exported by export -f?

In script.sh: #!/bin/bash func(){ echo "I am here a func." } export -f func export variable="I am here a variable" sudo -E bash -c "func ; echo $variable" And the output came: bash: func: ...
3
votes
1answer
192 views

How is shell ctrl-C ctrl-Z sent over ssh?

I am trying to figure out exactly what is sent to an SSH host when I press CTRL-C in either putty or open ssh. All I am trying to do is send control codes pragmatically that are equivalent to when a ...
3
votes
1answer
205 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 ...
3
votes
1answer
227 views

Why can't I use tab for autocompletion in neovim over SSH?

When used locally on arch I can easily use tab for auto completion in vim when e.g. filling in a path with deoplete. If I SSH to this computer from my laptop then tab still works for completion. But ...
3
votes
0answers
44 views

bash multiline history with lithist option broken

i used to enable lithist option, which make bash history store in multiline, but one day, the lithist option not work. enabling lithist mean you can store multiline in one history entry. if you type ...
3
votes
0answers
60 views

How to avoid bash from accepting non-printable characters at the prompt?

I recently ran a command at my shell: # yum whatprovides xdotool Error: No Matches found However, my package manager actually has this package: # yum whatprovides xdotool xdotool-1:3.20150503.1-7....
3
votes
0answers
92 views

What does it mean if a process has an O or an I at the start of the line?

After running ps, I noticed that a couple of the processes had an O at the start of the line. In all my years, I've never seen this. I thought that the meaning of the indicator might be common ...
3
votes
1answer
616 views

Redirect echo in trap function back to stdout

I'm currently having an issue getting echo statements in my trap function to be printed to stdout. I'm redirecting all output (error and stdout) to a log file from a command that I run. But if it hits ...
3
votes
1answer
312 views

XFCE - Blank text in terminal

I've just performed a fresh install of Arch Linux on my laptop (ThinkPad A485, though that's probably not relevant here), and installed XFCE4. Everything seems to be working with the exception of one ...
3
votes
0answers
738 views

List all jobs in all shell sessions (not just the current shell), by current user

I know that the jobs command only shows jobs running in current shell session. Is there a bash code that will show jobs across shell sessions (for example, jobs from another terminal tab) for ...
3
votes
2answers
340 views

Unable to have a local variable with the same name as a global read-only variable

#!/bin/bash readonly x=2 function test { local x=1 echo ${x} } test echo $x The result is, readonly-local-test.sh: line 6: local: x: readonly variable 2 2 When the variable is read-only this ...
3
votes
0answers
62 views

Git - prune every whitespace-separated word originally introduced by specific author in project's history

We have a project under git revision control with only a single branch. We need to remove every new whitespace-separated word that was introduced for the first ever time in a given file by a specific ...
3
votes
0answers
419 views

Bash 4.4 change color vi mode

I am using +~ $ bash --version GNU bash, version 4.4.0(1)-release (x86_64-unknown-linux-gnu) Copyright (C) 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://...
3
votes
1answer
977 views

How to 'hash -r' and refresh all shells?

This is related to What is the purpose of the hash command? After installing a program I am looking for a way to tell all open shells to update their cache. I often have 6 to 8 of them open and I don'...

1
2 3 4 5
43