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
15 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
38 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
38 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
33 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
1 vote
1 answer
26 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
4 answers
49 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
2 answers
29 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
2 answers
58 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
17 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
37 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
19 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
52 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
230 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
486 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
1 vote
4 answers
67 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
  • 19
0 votes
0 answers
39 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,384
4 votes
1 answer
46 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
29 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
71 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
  • 333
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
2 answers
37 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
  • 595
4 votes
5 answers
395 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
  • 595
1 vote
2 answers
27 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
  • 113
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
68 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
32 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
0 votes
0 answers
25 views

Sway doesn't execute the script on startup

I have two bash scripts and I want them to run on startup. I'm using sway and I execute scripts with exec word like this exec /home/crawraps/.config/sway/gdrive-push-sync.sh exec /home/crawraps/....
user avatar
0 votes
1 answer
38 views

bash: URL: command not found [duplicate]

I keep getting the following error in bash (using windows): $ URL = "https://nyc-tlc.s3.amazonaws.com/trip+data/yellow_tripdata_2022-01.parquet" bash: URL: command not found The full ...
user avatar
  • 113
0 votes
0 answers
48 views

Can't find a bash script anywhere in filesystem

I have a bash script that uses ssh and requires 1 positional argument. If I type the name partially, the bash-completion completes it and the script works. The issue is that I can't find it anywhere ...
user avatar
  • 333
0 votes
1 answer
40 views

Add information to HTML table with awk

I am trying to get the numerical and percentage outputs of free together in a table, which I send to myself per mail. I have tried to combine these into one table for quite a while, but nothing seems ...
user avatar
-1 votes
0 answers
14 views

power-calibrate installed, command not found

Same goes for powertop strangely. I have re-logged in to my session, and rebooted, but that doesn't change anything... And using bash neither: What can I do?
user avatar
  • 139
2 votes
2 answers
115 views

Echoing/printing a bash `ls` command substitution without quotes [duplicate]

I have the following example: $ a="$(ls)" $ echo $a backups cache crash lib local lock log mail opt run snap spool tmp $ $ echo "$a" backups cache crash lib local lock log mail ...
user avatar
  • 271
1 vote
3 answers
61 views

How to find first occurrence of string in log file, set T/F value as variable, and record changes that occur

I'm not sure how to title this, but here's what I've got: A file with text like: [10:03:43] 10:03:35 22JUN22 ConUP CW1B1 T CW1B3 T CW1B5 T CW1B7 T [10:03:44] ...
user avatar
  • 11
-1 votes
1 answer
49 views

How to extract the characters after a forward slash using awk

How can I extract the substring after a / and compare the extracted value against another file ? cat file /abc|98357| abc/aabb|023947| xyz/0102|293847| pqr/pqrst|29384| 9864/truse|253123| expected ...
user avatar
0 votes
1 answer
25 views

Find files not read since period of time

Is it possible to find under #linux files that were not read since defined period of time? Reason to do that is to save space on my storage by finding files that are probably not necessary in my ...
user avatar
0 votes
2 answers
41 views

Calling an array based on a string's value [duplicate]

I need to call on an array in a bash script which name is defined by a string variable, like so: var="array" array=( 1 2 3 ) $var will always equal the name of an array #failed attempts at ...
user avatar
4 votes
2 answers
110 views

Setting up a name in the terminal Linux

My question is pretty silly, but could not find nothing on the internet that explained me how. The thing is that I want to have the name displayed in the terminal as: Server mpi@raspberry: ... $ but ...
user avatar
0 votes
1 answer
15 views

Show stdout and stderr in Zenith

I am trying to install .deb file by right clicking on it in Nemo. My Nemo Action Looks like: [Nemo Action] Name=Install Deb File Comment=Install %F Exec=<scripts/install_deb_file.sh %F> Icon-...
user avatar
  • 1,384
3 votes
1 answer
99 views

"Ambigous Redirect" for redirecting text to a variable

I'm making a shell script to limit the amount of time someone spends on a program but it gives me these errors: ./time_limit: line 26: $Log: ambiguous redirect ./time_limit: line 16: [: root: unary ...
user avatar
3 votes
0 answers
33 views

How Is Executable Found Without Leading Path Despite Its Location Not in Search Path?

This question is about understanding the reason(s) behind a perceived inconsistency between documented and actual behavior when calling an executable through sudo. When the secure_path option is ...
user avatar
  • 31
0 votes
0 answers
27 views

Bash script logging not working as expected with rsync jump server

I'm using a shell script below for doing some rsync on a remote host. By ssh to jumphost and from there ssh again and initiating the rsync as below. Here I need to capture the log start and end date. ...
user avatar