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.

Filter by
Sorted by
Tagged with
0 votes
0 answers
7 views

How to use a value from sub shell in parent shell

I'm not used to linux scripting and this is the first time I'm working on it so I'm struggling with the following problem: Code: while [ $pct -gt 80 ]; do flag=1; ls -tr | while read file; do ...
user avatar
0 votes
1 answer
14 views

Why are my /usr/local/bin programs being copied to /usr/local/sbin?

I can't seem to reproduce it now, but it seems that some of the programs I add to /usr/local/bin get added to /usr/local/sbin. I noticed this because I wrote a bash script that seemed to me, for ...
user avatar
0 votes
1 answer
24 views

find files that is stored in format yyyy/mm/dd

I have a cron job that runs at 1am and creates an index.html for yesterday and current day in the below yyyy/mm/dd format. I need to grab day -1 and send to users. How can i achieve this? -bash-4.2$ ...
user avatar
  • 1
1 vote
4 answers
33 views

Stuck at removing a trailing newline from a string variable

Sometimes simplest things take your time in shell scripting like crazy. Content='me \n you \n him \n' echo $Content > Names.txt When I open the Names.txt it has two empty lines at the end. I want ...
user avatar
1 vote
2 answers
27 views

How can I create a JSON object from an associative array in shell using jo?

I know about How to create JSON from associative array but that's not my problem. I have this associative array: declare -A aliases aliases[Index]=components/Index/Exports aliases[Shared]=components/...
user avatar
0 votes
0 answers
9 views

Turn a script do while to a systemctl service to intercept a tcp connection state

I made a little script that refresh browser, when web-server is down and connection is lost, with an infinite loop do/while true. I want to turn it in a service for a better and clean solution. The ...
user avatar
0 votes
0 answers
22 views

set -o vi in prompt leaves insert mode every time I use arrow keys and has warning bell constantly (bash/ksh)

I might use arrow keys to go back and edit a flag when typing a command in my prompt and doing so constantly kicks me back from insert mode to normal mode. How do I turn this off so it matches the ...
user avatar
  • 67
0 votes
1 answer
26 views

Why is “echo $SHELL” not captured by remote SSH output?

When I capture the output of a remote SSH call using cat, whether in bash or in Python, things work as expected. E.g, this works just fine: import subprocess rc = subprocess.getoutput(“ssh user@host; ...
user avatar
0 votes
0 answers
10 views

Subprocess launched inside a chroot created on a codespace with debootstrap fail with /dev/fd/62: No such file or directory

My goal is to standup a chroot with the basic Unix tool-set (bash, cp, touch, cat, etc) and any necessary dependencies need to run apt get inside a codespace. Using debootstrap gets me close. The ...
user avatar
1 vote
1 answer
45 views

IP address string manipulation problem

I am trying to build three octets 10.AB.C9 from a 5 digit number: 12ABC 12 = first octet AB = Second octet C = Third octet There are two scenarios with my existing code that can cause an in correct IP ...
user avatar
  • 323
0 votes
1 answer
13 views

Toggle screen resolution with a script, how?

How do I phrase a script that checks screen resolution with xrandr and changes resolution depending on what it is currently? Which is to say, toggles the resolution. Sample output of xrandr -q ...
user avatar
1 vote
1 answer
43 views

Bash output of date in bash script

I wrote this script: #!/bin/bash target="1.1.1.1" while true; do ping $target -c 1 -v > /dev/null if [[ $? -ne 0 ]]; then echo "$(date +"%d/%m/%y ...
user avatar
0 votes
2 answers
82 views

Why can't dot files in root directory be moved

There're some files, folders and dot files in a directory like following |-folder1 |----folder2 |----file.json |----file2.php |----.env |----.dockerfile |----.someconfig |----.dockerignore I run ...
user avatar
  • 1
0 votes
0 answers
13 views

Setting DISPLAY variable on a remote XServer session

I have a CentOS system running an X2go server and I use a client machine to connect to it. I'm trying to do some command-line automation for mouse-clicks using xdotool. The automation is scripted in ...
user avatar
0 votes
0 answers
12 views

zsh command expansion applies esacping [duplicate]

I have a string S, for which I want to replace every b character with \\ (two forward slashes). So this is what I have: $ S="abc" $ A=$(echo $S | sed 's/b/\\\\/') In bash I get the expected ...
user avatar
1 vote
2 answers
36 views

bash script: copy from a folder to another within a directory and loop the process over multiple directories

I am still a beginner for bash scripting.I am trying to loop copy command to run through multiple directories. I have set of directories, P1, P2, P3,..P60. Inside each directory there are three ...
user avatar
  • 13
0 votes
3 answers
35 views

Is there an equivalent to /dev/stdout for file descriptors 3-255?

I know that one can often trick command line utilities that expect a file to pipe into stdout out by passing /dev/stdout as the file name. I'm wondering whether it's possible to make a tool pipe to a ...
user avatar
0 votes
0 answers
5 views

How can I reverse backward-search to forwards-search and jump to next item with single type of C-s

I am using solution in unable to forward search Bash history similarly as with CTRL-r. To search backward in the history for a particular string, type C-r. Typing C-s searches forward through the ...
user avatar
  • 229
0 votes
1 answer
30 views

Pass bash variables to another application

I am trying to read some values from a file, save them in bash variables, and run docker by passing the values as environment variables. The file's structure is as follows: DB_NAME=db ROOT_PASS=...
user avatar
0 votes
1 answer
23 views

Is it possible to create a ncat loop?

If you had two computers, wanting to control one from another using only ncat, without using telnet, ssh or other networking tools and only two shells, how could i go about that? I have successfully ...
user avatar
0 votes
3 answers
36 views

Grep line containing a word OR has length in a specific range?

1598427@931 PDD 220624P00051000 ohlc=0,0,0,0 vol=0 oi=424 nbbo=69@2316/113@532 nbbo2=69@145/113@95 PDD 220617C00051000 ohlc=0,0,0,0 vol=0 oi=434 nbbo=530@1921/710@1496 nbbo2=530@31/710@115 PDD ...
user avatar
  • 103
0 votes
0 answers
18 views

Using install to copy same source file multiple times (with different names) into same destination

I'm trying to use install to write a series of automated steps to setup a subroutine. In one of the sections I need to copy a given file (logback.xml) to a specific location, but I need multiple ...
user avatar
  • 875
0 votes
1 answer
20 views

How to copy a file to a subdirectory path which is the same for multiple directories?

I wrote a git commit hook and tested it out in a repo called myrepo. I would now like to copy it to all the repos I have in my ~/repos folder. To do that I tried: $ cd ~/repos/myrepo/.git/hooks $ cp ...
user avatar
1 vote
1 answer
44 views

Bash function for 'Deep Replace' in file contents, file name, directory name, allowing for whitespace

On my Ubuntu system, I commonly need to do a 'Deep Replace' in file contents, the file name and directory name. For example when copying source code as a template for another application. I've put ...
user avatar
  • 121
1 vote
0 answers
14 views

Bash File Completion Creates Python Virtual Environment

Sometimes when I use tab file completion in a bash shell it pauses for one or two seconds before showing tab completion, and creates a Python virtual environment in my current directory. For example ...
user avatar
  • 11
0 votes
1 answer
28 views

Verifying a hashed salted password that uses yescrypt algorithm

In order to verify a password hash we can use openssl passwd as shown below and explained here openssl passwd $HASHING-ALGORITHM -salt j9T$F31F/jItUvvjOv6IBFNea/ $CLEAR-TEXT-PASSWORD However, this ...
user avatar
0 votes
0 answers
17 views

Wayland: Execute command in default terminal

In the past, I've been using x-terminal-emulator -e "$COMMAND" to launch commands in a new instance of the default terminal emulator while trying to be as compatible and DE independent as ...
user avatar
1 vote
1 answer
50 views

Fuzzy/non-deterministic behaviour for a simple Bash script

[root@localhost ~]# time cpumode Driver: acpi-cpufreq Boost: disabled Governor: ondemand Average and maximum frequencies now: 2159MHz 2929MHz Maximum allowed frequency is 3800MHz (out of 4928MHz)...
user avatar
2 votes
2 answers
226 views

Using jq in a bash script to get an element with a certain value pattern

I'm calling the homebrew api in a shell script with the goal of getting the App name for the item before trying to install it. Luckily the api provides this in an element called artifacts. Unluckily, ...
user avatar
  • 123
2 votes
1 answer
469 views

ufw "command not found"- but as the root user!

My Debian 11 VPS is running now for about 2 weeks- and today I just wanted to analyse, why my traffic is ~70GiB (counted by bashtop). So somewhere in the net I read about nethogs, that this could help....
user avatar
0 votes
3 answers
54 views

Given a weekday name, week of a month, and a year, how to find the date

I can find the last Monday using date -d 'last-monday' +%F but given a weekday name, week of a month, and a year, how to find the date? e.g. given: Monday, Week 4, June, 2022 output: 2022-06-20 given: ...
user avatar
  • 9
0 votes
0 answers
37 views

AWK command for summary statistics of array with several columns and a grouping variable

I got a data file with time-series data. Each line of the 5+ GB csv file freqs.csv has the appearance: start_freq stop_freq measurement1 measurement2 ... measurementk Frequencies are represented on ...
user avatar
0 votes
1 answer
54 views

create first come first serve with bash script [closed]

#/bin/bash sort(){ for ((i = 0; i<$n; i++)) do for((j = 0; j<`expr $n - $i - 1`; j++)) do if [ ${arrival_time[j]} -gt ${arrival_time[$((j+...
user avatar
0 votes
0 answers
5 views

Stuck during login on server - conda related?

When I am login to my server, the terminal halts and I have to hit CTRL+C to continue and entering the server. After hitting CTRL+C I get a lot of warnings (?) related to condo I believe. Any idea ...
user avatar
1 vote
1 answer
37 views

bash looping over files while tailing logs

I'm running a daemon that process files in a specific dir. I want to process those one by one. so idea is I will copy files 1 by 1 in daemon dir, and tail its log, 2nd file should be copied to daemon ...
user avatar
  • 1,703
0 votes
3 answers
45 views

Process the same stdin two time and append the outputs

I have a json file that looks like: [ { "key": "alt+down", "command": "-editor.action.moveLinesDownAction", "when": "...
user avatar
  • 1,329
4 votes
1 answer
36 views

zsh: pass variable by reference, and modify its value (like bash's local -n namerefs)?

Is it possible to pass a variable to a zsh function, and modify its value without using eval? I came across a bash way to do that: local -n: https://stackoverflow.com/a/50281697
user avatar
1 vote
2 answers
34 views

Script to find all empty git repositories on a machine

We know an empty git repository only has the .git directory in it. I want to find all git repositories on a machine, which are empty. I thought about this process: Find all directories that are named ...
user avatar
1 vote
1 answer
25 views

capsh works but systemd doesn't - Openvpn unprivileged user

OS: Debian 11 Package: OpenVPN 2.5.1 Background: After an update, Openvpn-2.5 clients can no longer use iproute to modify the interface and configure routes pushed by the OpenVPN server after root ...
user avatar
  • 87
0 votes
3 answers
67 views

Better way to convert IP?

I am trying to convert 10.AB.C9.XYZ to 10.AB.C2.252. Right now I am extracting each character and piecing them together. ip_main=10.AB.C9.XYZ A_char=${ip_main:3:1} B_char=${ip_main:4:1} C_char=${...
user avatar
  • 323
0 votes
1 answer
39 views

Possible to match multiple conditions in one case statement and pass them as variables?

I have a bash script where I want to set a case variable. For file1 there are two different NUMBER variables that I then I want to pass to a text file. I have tried the following: case $FILE in &...
user avatar
  • 1
0 votes
0 answers
19 views

Use of makefile varriable in Batch script [closed]

I have a variable in my makefile (mybuild.mak). The makefile has a variable. i.e BUILD_PATH = D:/<some path> The variable BUILD_PATH is to be used in a batch file (RunTest.bat). How to use the ...
user avatar
0 votes
2 answers
34 views

How to correctly line break and concatenate a string in a bash script

I have a Bash script with a function to log messages with time and status, and I want to keep my script 80 column only: #!/bin/bash log_message() { echo "[$(date)]-[$1] : $2" >> log....
user avatar
  • 593
4 votes
5 answers
335 views

Finding the line number of first occurrence of a text in bash script

I need to find out what is the line number of first occurrence of a given search string that should be in the start of a line in a text file and store it in a variable in my bash script. For example I ...
user avatar
  • 593
1 vote
2 answers
23 views

substitute 2 substrings from a single line in a file into 2 different lines in a different file from command line

I have a text file with however many lines. One line is: fixed_stringA = 123, fixed_stringB = 456 I have a second text file (again with however many lines). These 2 lines are in this order, in middle ...
user avatar
  • 111
0 votes
0 answers
40 views

mv throw error when executed in shell script

OS: Ubuntu I have the folder testfolder/subfolder with content backup file1.txt file2.txt testFolder And I have script testfolder/testMv.sh Now I'm inside of the bash session and do the following: ...
user avatar
0 votes
1 answer
32 views

How to elude using eval set -- for parsing arguments?

While studying the parsing of arguments by bash scripts using getopt, I have almost everywhere watched the use of this construction: eval set -- "$SOMETHING_PARSED". For example, here and ...
user avatar
  • 103
1 vote
0 answers
64 views

Shell script does not run at desktop startup

I have a simple script that I want to run at startup but it doesn't get run. The script is simple, it just swaps right Option key with right CMD key on my Apple Magic Keyboard: #!/bin/bash xmodmap -e &...
user avatar
  • 371
0 votes
1 answer
70 views

What does backticks do when in beginning of line in a bash script

I have noticed a weird behavior when a backtick is used in the beginning of line in bash scripts. example 1: echo "Test" `ls` Output: Test and ls is ignored. example 2: `test ':";`|)...
user avatar
0 votes
2 answers
30 views

Get value from a key value pair separated with pipe

I have a string as below Delete :xna.del|mode:Full|Execution: loaded I need my output to be stored in 3 parameters. for an example a=xna.del b=Full c=loaded
user avatar

1
2 3 4 5
486