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
3 answers
63 views

Bash expansion repeat a string n to n times

I'm trying to find combinations of characters that fit a (c)v pattern for up to n syllables, and so started by using expansion like echo {,p,t}{a,i} for all the possibilities for one syllable (using ...
guest4308's user avatar
0 votes
0 answers
24 views

ipsweep bash script not working (name or service not known)

I coded a bash script for an ip sweeper however it keeps giving me ths "name or service not known" output. Here is the code : And here is the output when I run the script : Can you please ...
TomPps 1704's user avatar
0 votes
0 answers
36 views

version-check.sh: line 1: !/bin/bash: No such file or directory [closed]

I am trying to build an LFS system. When I run the script it tells me version-check.sh: line 1: !/bin/bash: No such file or directory I have looked inside my files and the bin/bash file is present. I ...
Noah Villanueva's user avatar
0 votes
0 answers
12 views

How to use entr to duplicate a folder every time a contained file changes

I've never used entr before, but I intend to write a command in /etc/rc.local to copy the contents of a folder into another folder, every time a change is made inside the original folder. For this ...
1toneboy's user avatar
  • 103
1 vote
1 answer
25 views

Access values of associative array whose name is passed as argument inside bash function

I've some associative arrays in a bash script which I need to pass to a function in which I need to access the keys and values as well. declare -A gkp=( \ ["arm64"]="ARM-64-bit" ...
c10's user avatar
  • 13
0 votes
1 answer
40 views

Is there a tool for collapsing output of a command base on regex?

Let’s say I have a command that outputs the state of some application. This command runs forver (or until C-c) and outputs a single line when something happens inside the application. It outputs the ...
Uy Hà's user avatar
  • 101
0 votes
2 answers
54 views

What is the hot key to show the next command of the previous command in history in Linux/bash?

In Windows cmd window, let's say I type and execute 40 commands like this: echo 1[Enter] echo 2[Enter] echo 3[Enter] ... echo 40[Enter] If I decide to repeat the 40 commands again, in the same order, ...
zwhconst's user avatar
  • 113
1 vote
4 answers
359 views

How to get the current value of LC_CTYPE etc. in Bash?

Basically, how to achieve this in Bash? Parsing the output of locale - declare "$(locale | grep ^LC_CTYPE | tr --delete '"')" - seems yucky, as it involves four separate commands. ...
l0b0's user avatar
  • 50.9k
0 votes
4 answers
72 views

Loop through array in specific order

I have an array that may or may not contain BMC, and I'm looping through each element of the array. If it does contain BMC I want BMC to be the last iteration of the loop. The array is created with ...
jesse_b's user avatar
  • 36k
0 votes
1 answer
48 views

Can't interact with a file with an apostraphe directly in bash

I have a file titled "I'm Here.mp3" when I try to interact with it with ls, cp, mv, anything, it returns cannot stat "./I'm Here.mp3": No such file or directory. I tried double ...
phenivol's user avatar
0 votes
2 answers
62 views

Fitering rows of one CSV file based on two values from another file in Bash

I have two CSV files. One is long with columns: Chr_Name, h, j, start_pos, end_pos. Another is short file including columns Chr_Name and position. I need to filter the rows from the first file based ...
nishat's user avatar
  • 1
0 votes
1 answer
68 views

How to compress multiple files quickly using tar

I need to transfer multiple files to a HPC cluster. Currently, I've been using the scp command but it takes about 10 minutes or more to transfer one file (about 1.4GB each). I've seen that using tar ...
Shayma 's user avatar
7 votes
2 answers
970 views

LD_PRELOAD does not work and LD_DEBUG shows nothing

I use LD_PRELOAD to overwrite the read function. For a minimal test application it works fine, but if I test it with a larger application it does not work anymore. Also LD_DEBUG=all does not show ...
Kevin Meier's user avatar
1 vote
3 answers
62 views

Run nested local bash functions via ssh

I have a script like this that declares many functions which use another functions, etc.: #!/bin/bash function a { ... } function b { ... a ... } ... And another script that uses ...
k1r1t0's user avatar
  • 133
1 vote
1 answer
47 views

Is there a way to make a comment after a "\" has been used to split a shell command onto differemt lines? [duplicate]

I am using arch and bash. Everything is up to date. I have this command which works just fine yad \ --timeout=2 \ --undecorated \ --posx=1200 --posy=633 \ --title=" " \ --window-icon='/home/$...
Kes's user avatar
  • 799
1 vote
2 answers
40 views

How do I make sed delete a block of indented text below a non-indented line that also contains particular regexp, but not beyond?

I've been fighting with GPT, the sed documentation, and regex for almost my entire day. I'm trying to parse through files that contain cisco prefix-list configurations and print out the lists that ...
vessl921's user avatar
0 votes
0 answers
41 views

glob expansion not working even with shopt -s extglob set

I am trying to chmod -R 644 /tmp/work/* in bash script, however I get following error: #!/usr/bin/env bash shopt -s extglob set -eu mkdir -p /tmp/work/ chmod -R 777 /tmp/work/ sftp -o ...
Maven's user avatar
  • 141
0 votes
1 answer
36 views

how to execute command and log only the command to a file

I'm trying to run a command and log only the command to a file. I've tried using exec 4>test|command >&4|exec 4>&- but doesnt' work. If I run the commands separately it works but ...
dsaizt's user avatar
  • 11
0 votes
1 answer
189 views

what does this bash snippet do?

I am not very bash-fluent, but I really need to comprehend what does the following mean and what is the explanation? The code is not mine, but I trust the source I am especially bothered by the ...
gai-jin's user avatar
  • 135
1 vote
1 answer
228 views

Is there a way to alias "redirect stdout and stderr to a file"?

Relevant Context: Redirect standard out command > file command 1> file Redirect standard error command 2> file Redirect standard out and standard error to separate files command 2> ...
Daniel Kaplan's user avatar
0 votes
1 answer
47 views

how to write function with nested commands [duplicate]

I'm trying to write a find and cd function like so: findcd () { cd "$(dirname "$(find '$1' -type '$2' -name '$3')")" } to be called like so: find . f [FILE_NAME] But it's ...
Mathew's user avatar
  • 125
-5 votes
0 answers
60 views

I need to sort files in recursive list, but there are some difficulties [closed]

I got some problems when I was doing the task: Output the first four elements of a recursive list of file names and attributes in the lib0 directory containing the string "ra", sort the ...
Kamilla_T's user avatar
-1 votes
0 answers
58 views

How do I make a .bashrc shell function interactive?

eshark() { ssh root@$1 'tcpdump -i $2 port 5060 -vv -s0 -Uw - ' | sudo tshark --interface - --print -w $3.pcapng } When I run this, on a Linux machine, it says capturing on stdin whereas when I run ...
David Conway's user avatar
-4 votes
2 answers
159 views

Append not working well in bash [closed]

I noticed that the operator ">>" doesn't work well in my script and I don't know why. I have a script like this: for file in $(ls folder)` do echo $file >> text.txt done Into ...
BelBillo007's user avatar
3 votes
2 answers
322 views

Piping and input stream redirection to same command, which input does command take?

I was trying to run the command given below cat numbers.txt | sort < words.txt The above command has a pipe from cat command feeding to input stream of sort command. But at the same time, input ...
Abhishek P G's user avatar
0 votes
2 answers
40 views

Unable to pass AWS CLI commands in double quotes in json syntax

I'm working with the below script,getting syntax error as unable to fetch credentials from secrets manager. "username":"AWS CLI command of access Key i have entered", "...
code userit's user avatar
0 votes
0 answers
18 views

Why does the output in following command get written to second file rather than first file [duplicate]

I was learning about I/O redirection and tried out the following command. ls -l /bin/ > bin_contents.txt > bin_contents_copy.txt I do understand that redirection doesn't work between files. But,...
Abhishek P G's user avatar
0 votes
0 answers
11 views

mixup TCP sessions in pcap file to new pcap file

I need to shuffle TCP sessions from pcap file to new file. How can I do it? The following scripts don't work for me. To mix up sessions in a pcap file using Tshark or Wireshark, you can use the ...
Mexanizm456's user avatar
1 vote
1 answer
17 views

How to sync the commands I am typing with a document in Google docs?

I am working on installation of a software and making lot of changes in a linux box. Lot of times I am running 'history' to get list of commands and copy-paste into a Google Docs. Then I clean it for ...
Krish Singh's user avatar
0 votes
0 answers
19 views

Mailx call in shell script suddenly sending blank messages

Similar to what was reported in posting, MAILX sends an email but with a blank subject and body text, I have an Oracle EBS 12.2 server that's using a concurrent program (java) to invoke a shell script ...
mattp's user avatar
  • 1
0 votes
2 answers
36 views

renaming files based on matched pattern in another file

I have a list of files: out_CCGCGGTT+CTAGCGCT_R1.fq.gz out_TTATAACC+TCGATATC_R2.fq.gz out_GGACTTGG+CGTCTGCG_R1.fq.gz out_AAGTCCAA+TACTCATA_R2.fq.gz ... the adaptor IDs (between the two underscores, ...
Anna1364's user avatar
  • 1,016
0 votes
1 answer
49 views

bash: string variable contains asterisk. how to use this variable for searching etc with grep, sed?

Have a nice day I have got text file (zz.txt): Chemical name 3-Aminopropane-1-sulphonic acid Synonym(s) -- Homotaurine * Tramiprosate -- Chemical name Common name and synonyms ... I have variable s=&...
Alex Den's user avatar
0 votes
1 answer
33 views

How to reuse matched value in bash globbing? [duplicate]

I was wondering whether it is possible to reuse whatever was matched in a path with globbing? (Just as it can usually be done with regex substitutions?) I'm aware that there are other solutions for ...
flawr's user avatar
  • 115
1 vote
1 answer
53 views

How to auto connect to wifi in coffee shop with bash script

I'm using Arch and bash and Openbox and everything is upto date. Hopefully this will help a few people I'm often in Starbucks. The method to connect is to their free wifi in the Uk is to Connect to ...
Kes's user avatar
  • 799
0 votes
1 answer
47 views

Bash script variable syntax: with some commands it works, with others it does not [duplicate]

I do not understand the behaviour of this variable: SSH_CONFIG_FILE="~/.ssh/config" echo $SSH_CONFIG_FILE ls -l $SSH_CONFIG_FILE ls -l ~/.ssh/config This is the output: ~/.ssh/config ls: ...
Pietro's user avatar
  • 561
4 votes
4 answers
615 views

Can I extract complete dates from file with grep command?

I need help using grep to extract a zoned date time from a file on a Linux system. Source file is a XML with the data below: <item start="20231010073000 +0100" stop="20231010100000 +...
aris's user avatar
  • 43
0 votes
0 answers
30 views

Open GUI linux terminal in non-interactive mode

It would be helpful if I can open a terminal and run commands exactly as if they would be run by a non-interactive bash script, to test whether certain commands work in non-interactive mode without ...
user56834's user avatar
  • 125
1 vote
2 answers
657 views

How to modify a gzipped file with sed and then zip again the file?

I have a .vcf.gz file, with the following aspect: #CHROM POS ID REF ALT chr1 10894 chr1:10894:G:A G A chr1 10915 chr1:10915:G:A G A ...
Khaleesi95's user avatar
0 votes
1 answer
52 views

bash get output from command

I try to make a script for macOS that informs me about available software updates: result=$(softwareupdate -l) if [[ $(echo $result) = *"No new software available."* ]]; then say yes;fi But ...
Atalantia's user avatar
1 vote
1 answer
47 views

nnn file manager not allowing me to press r key for batch rename

I am using Arch and bash. All packages are current and up to date. I am using the nnn file manager. I go into nnn and make a selection of 3 files by pressing the space bar while over each of the three ...
Kes's user avatar
  • 799
0 votes
2 answers
83 views

Test if all three filetypes are present in a directory

I want to detect that there is one of each of the following filetypes in a directory .png , .txt, and .tar.gz. The following works correctly when testing for two of them shopt -s nullglob MYDIR=/...
teeeeee's user avatar
  • 187
0 votes
3 answers
52 views

Use bash to overwrite old file with a new file named according to current date

I am a complete beginner with linux, and need help making a bash script to create a file with a specific date in the file name. I have a directory called /backups/, in which I would like to create a ...
teeeeee's user avatar
  • 187
0 votes
0 answers
49 views

Bash AutoStart script does not copy files from shared folder

I have added a startup bash script to a device running Raspbian (Debian GNU/Linux 11 (bullseye)). This is my script: SysmacApp.sh #!/bin/bash mkdir -p /home/pi/App; mkdir -p /home/pi/Shared/Service; ...
McNets's user avatar
  • 101
0 votes
1 answer
49 views

How to list process with their depth?

I have a slightly different process tree question. I need to list the process and their depth in scalar value. pstree gives the result in a "graphic" manner. root 100930 0.0 0.3 ...
piovisqui's user avatar
  • 875
-1 votes
2 answers
77 views

Copy file from Server A to Server B

I have requirement to copy files from Server A to Server B And then move the copied files Server A to Archive folder I have written the script, but it takes the directory name differently. Copying ...
user3792741's user avatar
0 votes
2 answers
45 views

sed: update 2 similar variables in a file but keep the upper and lowercase

I have 2 variables in a file like below that I need to assign a new value inserted by one user input: read -p "Enter CName Name : " CName sid=C02SBX SID=C02SBX When I run the following ...
Ali's user avatar
  • 13
0 votes
2 answers
33 views

How to extend piped command by contents of variable?

I would like to extend this line that calls /usr/bin/mplayer for recording an audio stream. The referring script record.sh could get called multiple times in parallel and I need to know in which ...
user146500's user avatar
4 votes
5 answers
1k views

How can I make this script run in the background?

#!/bin/bash # Get the battery percentage for battery 0 battery0_percent=$(cat /sys/class/power_supply/BAT0/capacity) # Get the battery percentage for battery 1 battery1_percent=$(cat /sys/class/...
Lolis4TheWin's user avatar
0 votes
1 answer
82 views

Run `git commit -m` with single quotes in zsh

I sometimes use characters such as ! and $ in commit messages, they need to be manually escaped, but not if you use single quotes like this git commit -m 'My $message here!'. I tried to write a ...
Justin Breen's user avatar
0 votes
2 answers
51 views

How to define a multiple page ranges for pdftk with a bash variable

I'm using Arch linux, Openbox window manager, and bash. Everything is up to date with the latest versions. Can anyone tell me why I can't get the "$page_range" variable to show up within ...
Kes's user avatar
  • 799

1
2 3 4 5
511