Skip to main content

All Questions

Tagged with or
Filter by
Sorted by
Tagged with
12 votes
2 answers
1k views

I was debugging one script, and discovered unexpected behavour of handling arithmetic syntax error. Normally, when error happens, script is just continuing execution. #!/bin/bash func2 () { echo &...
Ashark's user avatar
  • 1,219
4 votes
0 answers
237 views

I am confused about the processing of SIGINT and EXIT traps in Bash scripts. I wrote this script to test: #!/usr/bin/env bash set -e exit_trap() { printf "In exit_trap \$?=$?\n" exit 0 ...
Alexey's user avatar
  • 2,380
2 votes
1 answer
87 views

I have a script read.sh: read -ei "hello world" eval $REPLY Upon executing chmod +x read.sh and then running ./read.sh, I notice that pressing Esc followed by b or w jumps between the ...
luna's user avatar
  • 25
0 votes
0 answers
40 views

I'm trying to monitor multiple log files simultaneously, but when I use: tail -f /var/log/app1.log /var/log/app2.log I get mixed output and can't easily tell which file each line originated from. What ...
Alphin Thomas's user avatar
0 votes
0 answers
37 views

The command echo ${PATH//:/$'\n'} should replace colons with new lines. However, I am getting spaces. What am I doing wrong here?
Florian's user avatar
2 votes
2 answers
357 views

I have a Bash script my.sh with commands such as: jup () { conda activate cd jupyter notebook } I source this file in .bash_profile with source my.sh and then I can run the command with ...
ginjaemocoes's user avatar
1 vote
2 answers
132 views

Consider this one-liner bash example: $ (function test() { echo "testing a string" | grep "a" | sed 's/i/y/g'; }; set -x; test | grep "test" ) + grep --color=auto test + ...
sdbbs's user avatar
  • 590
2 votes
3 answers
599 views

I have a bash variable as such HAP="$(echo ${d} | cut -f 7 -d '/' | sed 's/[A-Z,0-9]\+//' | sed 's/_//')" that when is run as part of a script return either ref or hap. Now, I have another ...
Matteo's user avatar
  • 387
0 votes
1 answer
75 views

In the tcsh shell, the elements of the directory stack can be access on the command line using =<#>, e,g, =0 =1 .... and a sampled command like: cp Something =1/ would copy file Something to ...
Evan Fishbein's user avatar
0 votes
2 answers
173 views

I want to alias cat to batcat. Yet I do not want to break any script on my system that may depend on cat. How to ensure that it won't break existing scripts? I am on an Ubuntu machine on a bash ...
k0pernikus's user avatar
  • 16.7k
7 votes
1 answer
1k views

There is a remote machine which I am accessing through ssh and every time I open a new shell either via login or tmux, I get asked for a sudo password. I have checked the .bashrc and /etc/bash.bashrc ...
Abhilash's user avatar
  • 669
2 votes
1 answer
173 views

When using the set -e flag in Bash, then it's difficult to get user-friendly error messages (a stack trace) and it's difficult to add cleanup code that executes before your script exits with an error ...
user3207874's user avatar
0 votes
2 answers
83 views

my vimrc seems to not play along with vipw/vigr (probably because i only allow root to place tmp/buffers/etc in a secure location) so I tried (using bash): user@host$ EDITOR='/usr/bin/vim -u NONE' ...
gcb's user avatar
  • 953
3 votes
1 answer
427 views

On my Linux Mint systems, when I type a command that is not found but is available from a package in the Ubuntu or Mint repositories, the command not found error message includes the names of the ...
kj7rrv's user avatar
  • 261
0 votes
0 answers
84 views

This is a fairly bog-standard script, but my bash knowledge isn't huge, so here goes. The script is from here - the Apache Cloudberry project - an interesting open source version of a distributed ...
Vérace's user avatar
  • 601
3 votes
4 answers
168 views

#!/usr/bin/env bash exec {BASH_XTRACEFD}>./xtrace.log declare -p BASH_XTRACEFD set -x { : "how do you hide this in ./xtrace.log?"; } 2>/dev/null # fail # { :; } "${BASH_XTRACEFD:-...
anick's user avatar
  • 611
-2 votes
1 answer
147 views

In the below shell script I want to extract the fields of a string delimited by | character. But unfortunately I'm facing issue if there exists pipe command | in the string, because of which I'm not ...
Harry's user avatar
  • 239
1 vote
1 answer
97 views

I'm surprised by the difference in manipulating the array between echo and printf in Bash: printf cannot handle += operator Both printf and echo cannot get results of += out of while loop So, why? I'...
Keelung's user avatar
  • 167
4 votes
2 answers
361 views

I have a command that takes always the same initial parameters. I can create a variable to capture these parameters. Also, I need to pass the output of a subshell running the same command to the ...
k314159's user avatar
  • 533
0 votes
0 answers
103 views

I've got MacBook from work and try to make it work similar to Linux. This is my config for history in bash: # When the shell exits, append to the history file instead of overwriting it export ...
jcubic's user avatar
  • 10.5k
1 vote
2 answers
373 views

In the below shell script, I am trying to get the process id of a remote process using ps command, but not getting the required output #!/bin/bash get_process_id() { local res local ...
Harry's user avatar
  • 239
0 votes
1 answer
98 views

bash 4.4.20(1)-release. (No portability required.) This function works great when I pass it a valid DB name: Get_ValidDB() { local pDB=$1 [ -z $pDB ] && { printf '||Requires a DB name.'...
RonJohn's user avatar
  • 1,483
-3 votes
3 answers
160 views

In the below shell script I am passing an integer and a string array to a print function which should print each parameter separately, but I'm not able to. I don't want make a reference of passed ...
Harry's user avatar
  • 239
-2 votes
3 answers
189 views

I need a part for a script in bash where hashes are generated automaticaly and continuously and when I press a key the generation stops and the last hash at which I stopped is displayed. I've cobbled ...
Orhan's user avatar
  • 65
1 vote
2 answers
155 views

In bash I can use local -n ref_name=$1 to pass an argument to a function by reference, but the same syntax in ksh throws an error saying typeset: -n: unknown option I tried nameref ref_name=$1 ...
Harry's user avatar
  • 239
1 vote
2 answers
100 views

bash 4.4.20 and jq-1.6 on RHEL8 I get this nice output from jq and column. Hard to read, though. pgbackrest info --output=json \ | jq -r '.[] | .backup[] | "\(.type) \(.label) \(.info.delta)...
RonJohn's user avatar
  • 1,483
1 vote
2 answers
136 views

If I alias a keyword, I can't figure out how to bypass it. $ alias if='echo "GOTCHA!"; if' $ if true; then echo y; fi GOTCHA! y The usual tools for bypassing an alias, like escaping, ...
wjandrea's user avatar
  • 722
1 vote
2 answers
268 views

In Bash I can use $(type -t function_name) = "function" to check if the function by name function_name exists or not in a sourced file which is sourced using source file_name command. I'm ...
Harry's user avatar
  • 239
0 votes
0 answers
47 views

Our goal was to create an AP mode on a Raspberry Pi easily, so we could connect to it from outside, connect to a webserver, send form details about the WiFi network, and then connect to that WiFi ...
Leskó Zsolt's user avatar
1 vote
1 answer
86 views

I have the below shell script which works fine in Bash to list all the directories residing inside a given directory path and add them to an array. But the same script code doesn't work in KornShell. ...
Harry's user avatar
  • 239
0 votes
0 answers
35 views

I wanted to use tee /dev/tty to look into the stream passing through a pipeline. While making some tests, I observed the following: ~$ cd /proc/self/fd /proc/self/fd$ ls 0 1 2 255 # Ok /proc/self/...
The Quark's user avatar
  • 454
2 votes
1 answer
264 views

Consider: heightScaled=$(bc <<< $H*$S/1) echo $heightScaled 45.0 Why am I getting 45.0 despite the same operations yielding 45 if used outside the script either interactively or piped into ...
VoQZ's user avatar
  • 29
3 votes
1 answer
459 views

I don't understand the following: $ cat <(sleep 60) & jobs -l [1] 63813 [1]+ 63813 Running cat <(sleep 60) & /proc/63799/fd$ ps --forest PID TTY TIME CMD ...
The Quark's user avatar
  • 454
3 votes
7 answers
1k views

In Linux in a folder, without subfolders, there are many files like this scheme. I list them with ls -1. 1yBWVnZCx8CoPrGIG.part01.rar 1yBWVnZCx8CoPrGIG.part02.rar 1yBWVnZCx8CoPrGIG.part03.rar ...
Banana's user avatar
  • 241
5 votes
1 answer
309 views

In bash, the following command printf 'foo bar\n' | { read a b; printf '<%s> <%s>\n' $a $b; } produces the output <foo> <bar> In fish, the following command printf 'foo ...
enzotib's user avatar
  • 53.5k
4 votes
4 answers
878 views

Hello i try to check if a path exists with a if statetment in a bash script from a string. I try the follow but nothing seems to handle this. The path is /home/orhan/Blog/Mai1 path='/home/orhan/blog/...
Orhan's user avatar
  • 65
0 votes
7 answers
2k views

Bash allows to export read-only variables and functions to the environment. Also, when a bash script is run, Bash sources the file BASH_ENV was set to, unless invoked with -p. How do you protect ...
anick's user avatar
  • 611
2 votes
2 answers
397 views

I want to know if there is another alternative in Bash to execute multiple blocks when the pattern matches. I don’t want to use another command, if statements, or two or more separate case blocks or ...
ReflectYourCharacter's user avatar
0 votes
1 answer
65 views

My VMs IPv6 address occasionally get on a blocklist. Their "evidence" is that they claim something is making outbound connections to port 25 and issuing an EHLO of an IP address, not a ...
John Oliver's user avatar
3 votes
6 answers
252 views

I'm trying to clean files that are copy/pasted versions of my Cygwin (mintty) terminal running bash1. Usually, the input and output are separated by a linefeed ('\n'), as expected. However, when I ...
bballdave025's user avatar
4 votes
4 answers
577 views

Given this code: #!/bin/bash set -euo pipefail function someFn() { local input_string="$1" echo "$input_string start" sleep 3 echo "$input_string end" } function ...
k0pernikus's user avatar
  • 16.7k
10 votes
7 answers
1k views

I am writing a script that locates a special type of file on my system and I want to check if those files are also present on a remote machine. So to test a single file I use: ssh -T user@host [[ -f /...
Nunkuat's user avatar
  • 203
4 votes
1 answer
260 views

Sometimes, a command is stalled attempting to write to a FIFO/pipe that no other process is currently reading from, but typing Ctrl-Z to put the process to the background by sending it the SIGTSTP ...
The Quark's user avatar
  • 454
2 votes
6 answers
712 views

Please see my linux bash script below. I can't achieve my target output with my current code. It keeps reading the whole column 4. input_file.txt: REV NUM |SVN PATH | FILE NAME |DOWNLOAD ...
user765641's user avatar
-4 votes
2 answers
205 views

Both of them use bash, but the one used on arch linux has way better auto-completion. But why is that? Both of them claim to use normal Bash, so how can that be true? I forgot to clarify that what I ...
Sul4ur's user avatar
  • 43
1 vote
1 answer
417 views

Wanted to run a script -- with option ./myscript.sh -a -g test -- without option ./myscript.sh -a -g The script looks like in below snippet, but don't see below script working correctly. The getopt ...
Tim's user avatar
  • 113
2 votes
2 answers
428 views

RHEL9 Sometimes server 1 has the secondary address 10.143.170.80/24, and sometimes server 2 has that secondary address. My script needs to test which server has that secondary address. However, ip ...
RonJohn's user avatar
  • 1,483
-2 votes
2 answers
113 views

so trying to capture history with date and readable timestamps AND the command should appear on same line. following is failing: Bash ver is: GNU bash, version 4.4.20(1)-release (x86_64-redhat-linux-...
Rajeev's user avatar
  • 268
1 vote
0 answers
64 views

I'm trying to use Linux bash config on a mac. I don't use zsh only bash on my mac. I have problem with this variable: # After each command, append to the history file and reread it PROMPT_COMMAND=&...
jcubic's user avatar
  • 10.5k
0 votes
0 answers
81 views

Context To restore the standard input, standard output and/or standard error (file descriptors 0, 1 and/or 2 respectively) of a process to the keyboard and/or display of an interactive shell (bash) ...
The Quark's user avatar
  • 454