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
1 answer
44 views

Bash Script: On Some command fail. Ask user to continue to next command or edit the previous failed command anv rerun it and then continue to next cmd

I have script. I want to do is when some command fails (note conditionals not matching must not be considered as fail) only when certain command fails script should pause and display user the failed ...
  • 9
0 votes
0 answers
23 views

export environment variables in k8s command is not working

In a k8s yaml config, the command is set as follows: When the pod launches, there's no PYTHONPATH enviroment variables, could anyone help explain? Thanks soo much!
  • 205
-1 votes
2 answers
661 views

"KeyError: 'non-free-firmware'" after running apt-get update

Running an update with the following command : apt-get update returns : Hit:1 http://kali.download/kali kali-rolling InRelease Traceback (most recent call last): File "/usr/lib/cnf-update-db&...
0 votes
2 answers
54 views

How to use 'pgrep' from a script, when the checked process includes a '-c' (that 'pgrep' considers an argument)? [duplicate]

The following script demonstrates my problem, which is to determine if the sox_user_auditd_v2r -c process is running: $ cat ./pgrep_stackexchange_sample.bash #!/bin/bash -xv quoted="\'$@\'" ...
0 votes
0 answers
19 views

How to identify HSAT1 repeated sequences from the FASTA (contains only them but multi-stretches) files and compute the frequency of occurance?

I am looking for something in a shell that helps me to first identify the patterns and then count them as how many times they are present. Importantly if I may be able to get the location start and ...
14 votes
9 answers
1k views

How to select a sub-range of the files in the current directory in a script/on the command line, based on e.g. alphabetical order?

In a file manager you can usually select a file, then hold Shift and select another file. Every file in between will be selected. I want to do the bash / zsh equivalent of this. I.e: I want to give 2 ...
0 votes
1 answer
27 views

Dynamic variable references

I want to define a variable my_stacklist with the value for {mypc}_stacklist so if mypc=kast I get to access the content of kast_stacklist via my_stacklist. I thougt this was the same as my earlier ...
  • 5
0 votes
0 answers
107 views

Format date to another date format in bash

I am retrieving the following dates from a database: 2022-04-12-08.22.28.940722 2018-10-30-10.28.10.112309 2022-04-07-14.13.19.426219 In my bash script I am writing them to a file (where the date is ...
1 vote
2 answers
70 views

Bash - how to recursively copy functions used in a function to another script(sharing my .bashrc file with others but only relevant part)

How can I share my .bashrc file but only relevant part? For example I created 5 functions in .bashrc: f1() { ... } f2() { f1 ... } f3() { f2 ... } f4() { f1 f3 ... } f5() { ...
0 votes
1 answer
95 views

put multiline variable value to a curl message in telegram

I want to send $log as a message in telegram using curl. It works when the variable value is one line only but I'm getting the error curl: (3) Illegal characters found in URL when its not (when the ...
  • 3
1 vote
1 answer
49 views

How to prevent 'pgrep' to consider the expression it checks as containing arguments for it?

I have the following script; it is supposed to start a process if it is not running: $ cat keepalive_stackexchange_sample.bash #!/bin/bash -xv # This script checks if a process is running and starts ...
2 votes
1 answer
37 views

How to add a substring to a string as a column

The title may not be the best at describing the issue, but this was the best I could come up with, moving on to describe what I'm trying to do, I use artix runit as my os, and it is tedious to create ...
2 votes
2 answers
136 views

How do I attach a bash shell to a named pipe?

Let’s say I have two containers X and Y (two containers in the same Kubernetes pod, actually) that share a volume. On that volume is a named pipe /foo that I want attached to a bash process on ...
  • 143
0 votes
1 answer
58 views

passing shell script file name as an command line argument java -jar /test.sh and gives me error Error: Unable to access jarfile /test.sh

java -jar /test.sh --name trigger Error: Unable to access jarfile /test.sh test.sh file contains #!/bin/sh jar_name="-Dspring.config.location=application-test.properties somejarFileVersion_1.0&...
1 vote
1 answer
72 views

Ubuntu on Windows Terminal Hanging After Creating an Alias for Starship Prompt

Distro: Ubuntu-18.04 (running on Windows 10 WSL2) My terminal for any new Ubuntu instance is completely frozen with the message "Vim: Warning: Output is not to a terminal" This happened ...
0 votes
1 answer
56 views

Bash : Add all directories to variable exclude some

I want to add directories to a variable as such: WATCHED_DIR="\ someDir_1/* \ someDir_2/* \ someDir_3/* \ Each directory has a lot of sub directories and most of the time ...
0 votes
1 answer
35 views

read path with acronized spaces

I wrote simple bash script which merge n dicts: #! /bin/bash file_out="res.dict" start_time=$(date +%s) count_overall_before=0 while read -rep file in "$@" do count_in_file=$(...
1 vote
2 answers
76 views

Match date pattern that precedes SED range match and include the matching range in output

Having issues with trying to set variable (example: str_pattern) with multiple values and then using those in sed command to match range in reverse to previous blank line or back to ExecuteThread. ...
0 votes
1 answer
26 views

How to loop trough wtmp and extract certain data?

I am using the following command to save wtmp (last command) to a logfile: last -F | grep -i -e pv -e nv -e pp > last.log Result: I want to extract the username (first block) and the time of ...
0 votes
1 answer
26 views

Line colouring fails for Syp: and Code:

I am using the following bash function to print a multiline strings in colour. desc=" Syp: {-W,-w,--wht} -f FILE Print Syp brief Red: Some red details here. Code: Some code here ...
  • 83
0 votes
3 answers
67 views

Curl not working in Loop from list of URLs text file

I have a text file with about 50 URLs Am trying to curl each of the URLs in the text file and grep to output a couple of lines from the GREP Match I cannot understand why it wont work, as if i echo ...
1 vote
2 answers
117 views

split folder in subfolders keeping parent directories and based on percentage. Using terminal

I have a directory with many subfolders that look like the following, (keep in mind that FA and T1 content is paired and also ..._L, ..._R content). The quantity of folders named here by letters (a,b,...
  • 13
1 vote
1 answer
37 views

How to iterate over a directory for files without including sub-directories in Bash

I need to parse through a directory that contains files and subdirectories however I am unable to use the find command. The for loop is supposed to go through each file and compare it to another ...
  • 11
0 votes
1 answer
61 views

Why won't bash run scripts with carriage-return characters?

I noticed that bash will refuse to run a script if it contains carriage-return characters at the end of its lines. To observe this create a file hello.sh: #!/bin/bash echo hello Now give it execute ...
0 votes
2 answers
42 views

How to add file markers to check if script is already running

I wonder if I can get some help with a project I'm working on. I have a Synology NAS. I found a Community Package that autoruns a script of my creation anytime a USB drive is plugged in to one of the ...
  • 3
-1 votes
1 answer
76 views

use a variable as a variable

I'd like to use a variable variablenaam for using in a loop. I tried for hours but can't make it work. My experiment in bash on a RPi 4 with the latest Raspbian. I like to make the use of xstack1 and ...
  • 5
3 votes
2 answers
78 views

Indent Fortran source code, propagate indentation down to unindented special lines

I'm trying to write my own script to improve some auto-formatting before commiting to a remote repository. I use indenting guides in my IDE and the autoformatters available for my language (FORTRAN) ...
2 votes
3 answers
171 views

Colouring code parts of multiline variable in awk

I have a variable var. Want to print the lines after Code: in blue (but with the line specifying Code: removed), whilst the rest is printed in green. Am using a bash script that calls awk to do the ...
  • 83
0 votes
1 answer
69 views

Invalidity of awk printf in bash script

Why does the construction of the printf not valid? awk -v frg="$ctp" -v rst="$sgr" -v prl="$rl" \ '{ hit = match($0, /prl/) if (hit) { fm="%s%s%s\n&...
  • 83
1 vote
1 answer
36 views

Combine .csv-files with text between each line

I have two (or maybe more) files: file1.csv dog cats mouse file2.csv 001a 002a 003c If I use paste file1.csv file2.csv the output is dog 001a cats 002a mouse 003c Of course I can use paste -d ,...
  • 157
0 votes
0 answers
45 views

Gracefully quit "Install macOS Ventura.app" with Terminal

I have a script I would like to deploy to Mac endpoints which would quit the "Install macOS Ventura" installer app if it's open. I'm using the kill -9 <PID> command, and it doesn't ...
1 vote
2 answers
37 views

Tying to replace a file content with the machine current IP address

I have a yaml config file(cli.yaml). with structure database: host: "IP" Now, I just want to replace the file content, Or more precisely THE IP string with my PC's current IPV4 address. ...
  • 111
0 votes
1 answer
53 views

How to adjust the output of dbus-monitor?

I'm building a microservices application using the GNU tools and bash and I decided to use dbus-monitor and dbus-send for IPC between services. The problem is that it's hard to make use of the ...
0 votes
2 answers
40 views

Copy only the folders (and all their content) at the level of source path with rsync

I have the following tree, where f are files while src and d are directories (f could be hidden or not): src/f1 src/f2 ... src/d1 src/d2 src/d3 ... I want to replicate the same structure in a dst ...
5 votes
1 answer
83 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" ...
0 votes
1 answer
29 views

Why is it different to run bash with an argument vs with an input file redirection?

Why exactly is bash <script different than bash script? When i try this using a script that contains: cat hello world In the first case, i get what i expected: hello world But in the second case, ...
-1 votes
1 answer
53 views

numbering to each jq output

I have a JSON file { "fieldA": {"fieldData": "XYZ"} "fieldB": {"fieldData": "PQR"} "fieldC": {"fieldData": ...
  • 140
9 votes
1 answer
821 views

What does a hyphen do next to the argument position in bash shell script? Like ${1-}

I've come across this piece of code from here: #!/bin/bash # ... if [[ "${1-}" =~ ^-*h(elp)?$ ]]; then echo "Usage..." exit fi I understand what this does is print the ...
0 votes
1 answer
46 views

How to compare 2 files and print all the lines from 2nd file to output file bash script

I am trying to get the following output. I have 2 input files and we need only the common :names from both the input files along with there the lines below them the .name/of/file lines. Till now I ...
  • 21
-1 votes
2 answers
66 views

grep words containing numbers

I have two strings "Some Special xn39432n4 (foo bar)" "Another thing goes 21 deer 14.5" with sed, I want this output xn39432n4 21 deer 14.5 means all space separated words ...
  • 140
0 votes
1 answer
32 views

How to execute wine command through busbox?

I am building minimal operating system using busybox.I am writing init file, I want to call script1.sh file from init file. Challenges I am facing are: After running init file it is showing ./script1....
0 votes
1 answer
57 views

Coloured output subject to user defined pattern

I am interested in writing a bash function that prints the contents of a variable and highlights all the lines that match a given pattern. The following uses awk to process the lines in the variable. ...
  • 83
0 votes
1 answer
49 views

Cron job to run rmmod not executing at reboot

This is on Proxmox VE 7.3 with Debian 11. I ran crontab -e, added @reboot /home/onboot.sh to the file, saved it, ensured cron is running with systemctl enable cron.serviceand verified it's running at ...
1 vote
2 answers
77 views

Help with storing awk output in variable

I'm trying to write a shell script that does the viginere cypher with a given text and key and can't figure out how to save the new ascii number for the converted char in a variable. Code down below: ...
0 votes
3 answers
154 views

Glob pattern matching comma separated numbers

I want to write a glob pattern to match numbers separated by commas. What would the pattern be like? Here are some examples 5 5,8,13 Have started with the following, but there some problem with it, ...
  • 83
0 votes
2 answers
46 views

How to get the Path difference and store it in a variable

Suppose I have two paths. Path1 which is static and path2 which is dynamic. Example: Path1= /tmp/folder/ Path2= /tmp/folder/dir1/dir1_2 Result: Diff= /dir/dir1_2 I want to achieve as above example....
0 votes
2 answers
70 views

Why is echo "\*" the same as echo "\\*"

Title. echo "\*" has the exact same output as echo "\\*", \*. I am using GNU bash 5.2.15. I expected echo "\\*" to output \*, but I do not know why echo "\*" ...
0 votes
1 answer
51 views

Colouring lines in bash variable

I have the following bash function which prints lines from a string variable using colour. I want to use wl="1,5,8" so that lines 1, 5, and 8, are coloured in white. How can I do this? kls ...
  • 83
-3 votes
3 answers
69 views

shell script - checking multiple lines if value is smaller than

I have input files (.txt oder .csv) In this files are different values (sometimes no value -> ""). If ONE of this values is less than 0.001 (or empty -> "") the output should ...
  • 157
32 votes
1 answer
3k views

How to get the cd shell-builtin to stop guessing?

For example: $ ls -aF ./ ../ bin/ $ cd tin # with a tee, not bee bin $ pwd /home/user/bin In other words, cd guesses that what I really meant was cd bin, and successfully (huh?) changes the current ...

1
3 4
5
6 7
513