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
1 vote
1 answer
128 views

mate-terminal showing unwanted text when it starts

i'am on parrot OS, after a forced restart my mate-terminal begun showing text from bashrc every time it started, after a "clear" it goes away and the prompt is properly colored and ...
Ar Angelina's user avatar
1 vote
4 answers
97 views

Synthetic Variables in Bash (was: How to address a variable ceated with indirection) [duplicate]

Sorry, that was all too confusing, (my bad) Let me try to explain again, but with a more simple example: #define a new var and export it to the "env": export VAR_ONE=thisIsVarOne # check if ...
Chris V.'s user avatar
0 votes
1 answer
25 views

How do I correctly define and interpolate this variable into my find command? [duplicate]

I wrote a Bash script, mscript.sh for managing my music files, a part of it creates a list of such files. all_exts=" -iname \"*.webm\" -o -iname \"*.mkv\" " #all_exts=' -...
John Smith's user avatar
2 votes
3 answers
742 views

ARGV[] not accepting the argument

I have a shell script that I am trying to pass a date argument to ARGV[1] but the script is giving a blank output Here is the command: #!/bin/bash dt=$(date -d "yesterday" '+%m%d%Y') cat /...
NecroCoder's user avatar
2 votes
1 answer
43 views

Why does `read` fail saying "read error: 0: Resource temporarily unavailable"?

script #!/bin/bash -- # record from microphone rec --channels 1 /tmp/rec.sox trim 0.9 band 4k noiseprof /tmp/noiseprof && # convert to mp3 sox /tmp/rec.sox --compression 0.01 /tmp/rec.mp3 ...
Pound Hash's user avatar
2 votes
2 answers
83 views

bash - Is it possible to capture the output of several background commands without writing to disk?

I have a script with several pipelines that I would like to parallelize. It currently looks something like this: result1=$(pipeline | number | one) result2=$(pipeline | number | two) result3=$(...
JM0's user avatar
  • 201
7 votes
4 answers
2k views

Why does a backslash at the end of the line place undue whitespace?

I wanted: #!/bin/bash cmd --options \ option=value,\ option=value,\ option=value,\ option=value But running with bash -x I got: cmd --options option=value, option=value, option=value, ...
rhuanpk's user avatar
  • 385
0 votes
1 answer
71 views

Pipe sql query to find command

OS: RockyLinux 8.5 This command works wonderfully: sqlite3 files.db "select file from A;" | rsync -R -av --files-from=/dev/stdin /SOURCE /DESTINATION/Out result without pipe: sqlite3 files....
Gary Schermer's user avatar
0 votes
1 answer
76 views

Shell script to find and copy files from a painfully large unsorted folder

I have a folder is populated each day with a series of files, for example content1_20231110.csv, content2_20231110.csv, etc. For reasons out of my control, this folder holds an entire year's worth of ...
Sam McAlevy's user avatar
1 vote
1 answer
49 views

Change value in array using yq from mike farah

In my yaml file I have this persons array (it only has one element always) persons: - name: mario version: 1.0.0 city: Madrid how can I replace city to any other value using yq ?
Andre Silva's user avatar
1 vote
1 answer
87 views

Always source bashrc in AlmaLinux / RedHat based system

I have an infrastructure that mostly consists of Ubuntu machines and many users. We like to use X2GO for remote access, which works well. We now have an AlmaLinux 8.8 machine. When login onto that one ...
Simon T.'s user avatar
0 votes
0 answers
38 views

how to know graphic current user(s) and DISPLAY(s) by root

Gentoo, openrc, X11. Hi, For my suspend process, I need to get something like [user] [DISPLAY] for example: chris :0 I can do it with: for sessionid in $(/bin/loginctl list-sessions --no-legend | ...
Chris972's user avatar
0 votes
2 answers
102 views

In terminal, how to delete a word when cursor is within the word?

I want to achieve functionality similar to c + a + w or d + a + w in vim In terminal we have Ctrl + w for delete a word in the left and Alt + Backspace from the right But I was not able to find a ...
inderjot singh's user avatar
1 vote
2 answers
71 views

SSH Config Host Autocomplete Command not Autocompleting

I wrote a function to get my hosts from ssh config without getting wildcard hosts: sshConfAutoComplete() { cat ~/.ssh/config | \ grep 'host ' | \ sed ' s#.*\*##g; s#host ##g ...
Nickotine's user avatar
  • 396
1 vote
2 answers
138 views

How to extract and delete contents of a zip archive simultaneously?

I want to download and extract a large zip archive (>180 GB) containing multiple small files of a single file format onto an SSD, but I don't have enough storage for both the zip archive and the ...
Kumaresh Balaji Sundararajan's user avatar
0 votes
1 answer
33 views

OSX13; how to mv series of x numbers of file chunks simultaneously to the series of directories

I have a following list of files; 260704 96 -rw-r--r-- 1 MacStudio staff 47131 Jul 28 20:18 ./GSM7673474_30_CC0022.barcodes.tsv.gz 260705 6264 -rw-r--r-- 1 MacStudio ...
akh22's user avatar
  • 115
1 vote
1 answer
55 views

Execute Remote Script on Server by Means of SSH

I have a remote script on a remote server: #!/bin/bash echo Parameters=$@ echo "Ciao" $1 I run the script by invokin an ssh connection: ❯ pippo=pluto ❯ ssh -i ...
gdm's user avatar
  • 252
0 votes
2 answers
93 views

math problem or variable value problem im not sure

I am having an issue comparing epoch times. I'm really not sure what I'm doing wrong. I have been tasked with identifying and actioning files beyond and during certain date ranges. In this case, it's ...
Kevin Huntly's user avatar
-2 votes
0 answers
37 views

Preserve newlines using indirection in bash

I am parsing the output of curl -i ... in a script function. To handle the multiple outputs from the parse (header, body and etag) I am using indirection. While I am aware that using quotes when ...
symcbean's user avatar
  • 5,203
0 votes
1 answer
45 views

Scripting fdisk with filesystem signature issues

I'm trying to automatize fdisk with my Bash scripts. In my script, I have the following code block: echo "Creating root filesystem partition..." ( echo n echo 3 echo echo ...
izarc's user avatar
  • 13
-2 votes
3 answers
113 views

bash + how to verify folders under specific path are ended with number/s

I want to check the folder/s under /var/kafka that all them are ended with number otherwhile I will exit with error ls -ltr /var/kafka drwxr-xr-x 399 kafka kafka 28672 Nov 9 13:10 data6 drwxr-xr-x ...
yael's user avatar
  • 12.8k
-2 votes
2 answers
112 views

defining variables inside function

After some reading somewhere on this interwebs, I found that it was best practice to to the following when using the output of a command as a variable: FILE_CORE_NAME="$(/usr/bin/env basename $(/...
Kevin Huntly's user avatar
-2 votes
1 answer
226 views

Identifying Linux distribution from screenshot

A friend is asking me to help him out with this old linux box that he has which i believe it like over 15 years old. He only sent me this screenshot so I don't know much about it yet until i meet with ...
Singleton's user avatar
0 votes
1 answer
85 views

Add content to yaml file using yq from mike farah

This is a basic question but I am struggling to make this work as I have no experience in bash. Lets say I have a directory directory_1 and inside this directory I have cen1.yaml and cen2.yaml. cen1....
Andre Silva's user avatar
2 votes
1 answer
46 views

How to rename files to specific string in their filenames

I have large amount of .json files that need to be renamed to a specific string of numbers in each file's name. They follow the format: [Artist] Title (Date) [Language][Publisher][Website.####][Pages]....
fukaeri's user avatar
  • 23
21 votes
1 answer
3k views

Why does echo !() print the contents of the current directory?

I have been teaching myself the meaning of various bash 'reserved words'. In doing this, I inadvertently typed the command echo !() To my surprise, this command executes, and produces output ...
jrt's user avatar
  • 213
2 votes
1 answer
95 views

Escape special characters from variables [duplicate]

I have #!/usr/bin/bash search="ldo_vrf18 {" replace="$search"' compatible = "regulator-fixed"; regulator-name = "vrf18&...
Bret Joseph's user avatar
1 vote
1 answer
27 views

tmux new-window command plus argument including spaces - bash var

I'm trying to execute a command on a new tmux window. A simple console/terminal pdf reader. The script needs argument, a PDF file, the file name may include spaces. I've tried this: #!/bin/bash tmux ...
Krackout's user avatar
  • 2,567
6 votes
2 answers
515 views

How can I use ps and pwdx both together?

I have a Top command that I use to see what's going on in my server: ps -eo pid,cmd:50,%mem,%cpu --sort=-%mem | head 20 Basically it's using ps and removes a bunch of columns. For each process id I ...
Saeed Neamati's user avatar
2 votes
2 answers
560 views

pipe the read command?

I'm trying to pipe a string with special characters (e.g. HG@eg3,l'{TT\"C! to another command (termux-clipboard-set) with the read program. It seems that read was designed to create a temporary ...
Daniel Krajnik's user avatar
2 votes
2 answers
113 views

"set editing-mode vi" v/s "set -o vi" what is the difference?

On multiple forums I have come across adding set -o vi to my .bashrc file. Today I saw the option of adding set editing-mode vi to .inputrc. I googled and both appear to do the same thing, are there ...
Ishaan Kapoor's user avatar
0 votes
1 answer
62 views

How to open many pages with bash?

I am working on one of my test web projects and every time I finish my work and want to rest, I have to close 3, 4, 5, or more sessions on my termux. I'm using vim, and I have to go to the working ...
Sina Vasmas's user avatar
1 vote
1 answer
55 views

How to Create a Bash Script for Managing Temporary Files with Automatic Archiving and Cleanup?

Want a solution for managing temporary files in a Linux environment with a Bash script. If files are in a root folder and remain unmodified for 10 days, move the files to a subfolder and add a ...
ImportanceLow7312's user avatar
0 votes
0 answers
14 views

lftp crawl for any newly created files and download them

I have just mirrored a remote webserver using lftp's mirror command. However, the webserver updates regularly with newly created files, although it does not update any already existing ones. How can I ...
Anm's user avatar
  • 113
0 votes
2 answers
56 views

Why does bash regex fail for meta characters? [duplicate]

I am trying to do a bash script to check if input file name is of format name.json. The regx in bash doesn't work but it works with grep. file t1.sh echo "$1" regx="^[\w\d-]+[.]json$&...
preetam's user avatar
  • 117
0 votes
1 answer
55 views

Using Sed to modify php memory limit

I am writing a script that needs to modify the default php_admin_value[memory_limit] from 128 M to 512M. I don't get any errors when i execute the command from the CLI or from a bash script, but ...
n8dagr8's user avatar
2 votes
0 answers
55 views

The paste command is outputing tabs instead of new lines when used with process substitution

The first command below produces each number on a separate line, and I would expect the second command to do the same thing because the only difference between the two is that we are using echo '1 2 3'...
sudocracy's user avatar
  • 221
1 vote
2 answers
48 views

Bash, compare Array against file and output lines not matched

I've got a string array collected from a list of log files on a RHEL machine, and I want to identify unique lines in the array that do not have an identical matching line in a file, but I can't figure ...
Jay_name_goes_here's user avatar
4 votes
2 answers
552 views

How to get both the number of bytes and the sha1sum with single pass?

I want to get both the number of bytes and the sha1sum of a command's output. In principle, one can always do something like: BYTES="$( somecommand | wc -c )" DIGEST="$( somecommand | ...
kjo's user avatar
  • 15k
-2 votes
2 answers
77 views

Sorting a text file based on numerical values present in each line [closed]

I have a text file containing paths of various wav files. But when they are created they are sorted based on alphabetical order. Hence the paths are like this /home/wav_path/...
Turing101's user avatar
  • 153
0 votes
1 answer
49 views

Select, Case in if-else statement requires double inputs

I need to find out where is the problem. I need to write a script that prompts users to make Yes/No choice in if/else statement. In general I have a bash script that runs like this if CONDITION; then ...
enoughsaid05's user avatar
9 votes
1 answer
931 views

GNU Coreutils `\time --version` and `/bin/true --version` work but `\true --version` does not?

$ \time --version time (GNU Time) UNKNOWN Copyright (C) 2018 Free Software Foundation, Inc. ... $ /bin/true --version true (GNU coreutils) 8.32 Copyright (C) 2020 Free Software Foundation, Inc. ... $...
charmoniumQ's user avatar
0 votes
1 answer
31 views

Copy all files with the directory structure since the last run on remote server

I would like to scan for my /tmp/ directory now and then and check what files have been changed since I last time did it. All files that have been changed should be copied to remote server (as a ...
user avatar
0 votes
1 answer
68 views

declare: not found error in Jenkins pipeline

I have a Jenkins pipeline which has a step running a sh script. Something like this, but with more commands in between which are not relevant: steps { echo 'Running build with all ...
Catalin Nicolae's user avatar
4 votes
0 answers
178 views

Bash: Stderr being sent to a file (when it shouldn't be!)

The following code is on macOS as part of /etc/bashrc_Apple_Terminal, in order to save and restore the shell state across all open windows and tabs (note that this is therefore the very old bash 3.2....
Andrew Jaffe's user avatar
0 votes
1 answer
81 views

How can I write a function that returns the results of a one-line `node` script?

I'm trying to write a very simple bash function that uses a one-line node script to read the value of a key from a JSON file. Here's the current contents of utils.bash: #!/bin/bash project_name() { ...
Chuck's user avatar
  • 477
-1 votes
1 answer
49 views

different bash output for same input

I encountered some unexpected behaviour of my bash. This is my in-/output: nepumuk@pc:~$ type URL URL is a function URL () { echo -e "${_//%/\\x}" } nepumuk@pc:~$ URL %2f URL nepumuk@...
Nepumuk's user avatar
  • 657
-1 votes
2 answers
59 views

Numeric if conditions that read a command in a bash script

I'm trying to write a command that looks at my battery state and suspends the laptop if the battery is low. I tried using something like this: #!/bin/bash if [ $(acpi -b | cut -c 25) < 11 ] then ...
Alexander Praehauser's user avatar
0 votes
2 answers
34 views

bash using "find" in dir1 and delete these files in dir2

I have two folders. I want to find files with a specific extension recursively in dir1 and delete files which are found in dir1 from dir2. I think this can be done with -exec command in find. Deleting ...
DF8OE's user avatar
  • 33
0 votes
1 answer
41 views

Can I use tee to display output that other utilities tend to suppress?

The macos pbcopy utility grabs its input stream and stores it in the system clipboard, without displaying anything. So, when I want to copy/paste the output of a command in the terminal, I typically ...
JL Peyret's user avatar
  • 103