Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

1
vote
0answers
21 views

Execute a shell script on the remote server in the background

I have a list of servers and Bash scripts that need to be executed on a server. For example, I have a script that schedules a cronjob (with the command that the user has specified) on a server. This ...
0
votes
2answers
55 views

How to do vi edit on bash Linux?

Almost 5 years ago, used to do something like VIEDIT (forgot exact word I used to use). Usecase - when I want paste bunch of lines of program or strings I do something like viedit (again I forgot the ...
-1
votes
2answers
43 views

How to find avg, min, max and all for all file statistics (unix bash shell scripting)

I have a question regarding finding the average, minimum, maximum through shell scripting. Background: I have directories ranging from 1998-2019, there are 1,000 files within these directories. Each ...
0
votes
1answer
20 views

How to start and disown a process in a single line?

I noticed that many times I need to start a process and disown it immediately. I trying to achieve this in a single line. Any ideas how to do it?
3
votes
2answers
49 views

Bash ignoring SIGINT trap when 'select' loop is running

When i use 'trap' combined with select loop, namely when i try to hit CTRL+C to break out while options are displayed, it will just print ^C in terminal. If i remove 'trap' from script it will ...
0
votes
0answers
15 views

Passing variable to jq to edit a json file

I am trying to pass a variable into jq like this '.Linux.date.$var' so far I have tried quoting them by name which is working fine. But I want to use variable to call them. I have this, which is ...
0
votes
0answers
22 views

sed Shell Script not working correctly

I have this shell script that is supposed to go through a file and replace its primitive types with other specific text (it's for an assignment). The script is below: #!/bin/bash #Goes through an ...
0
votes
1answer
18 views

Find file while other file exist in same directory

I'm trying to do "one line script" or really small bash script. It have to find file (for example ./xxx/one.php) and if that file exist edit (with printf or echo) other file IN SAME directory (for ...
0
votes
1answer
24 views

compare a certain number of lines between columns of two files

I have a thousand files and I need to verify if they all have exactly the same information in the second column up to a certain number of lines. Below an example. I would like to print the names of ...
0
votes
1answer
21 views

Reading an argument and creating a tempfile from it to use within the script

I am trying to write a script that would count the number of columns in a file. However, I don't know what the name of the file will be. I am trying to create a file called tempfile which has the ...
-1
votes
1answer
21 views

How to append * to the String and assigning a prepared SQL Query to another variable? i.e., (select * from …)

I'm trying to create a SQL Query and trying to assign it to some variable but I couldn't do that. TABLENAME=foo QUERY="select * from $TABLENAME" echo $QUERY I'm expecting the Query would be select * ...
0
votes
1answer
45 views

Why can't I execute .bashrc directly and what is “sourcing”?

My .bashrc has the following permissions: -rwxr-xr-x So it's labeled "executable". My newbie brain tells me I should therefore be able to just run it. But when I try $ ./.bashrc I get: ./.bashrc:...
-1
votes
0answers
13 views

Dynamic Log Remove

I want to delete logs in Linux machines and the path example below. /test1/test2/test3/x/a/b /test1/test2/test3/y/a/b /test1/test2/test3/z/a/b Thing is directory changes after the "test3" folder I ...
0
votes
0answers
12 views

Merge multiple files with different extensions using a loop in bash script [duplicate]

I have 100's of files of the form filename.0 filename.1 filename.2 filename.3 And they all have identical layouts which I want to merge together into one file using a loop in my bash script, I have ...
-1
votes
0answers
33 views

Script that checks a process's running status

I need to make a script that checks if a java jar is running on a particular port or not.If the jar is not running then the script should run it automatically. let's say I want to check if my jar xyz....
1
vote
1answer
21 views

Starting wpa_supplicant via script in systemd not working properly

I've written a script to manually start the wpa_supplicant function on a Fedora/Centos7 machine with a wireless NIC. Due to static routing issues, I cannot use NetworkManager (nor do I want do with ...
0
votes
1answer
24 views

Bash String manipulation when string contains parentheses

I have a directory full of files with the name template xxx[0-9][0-9][0-9[0-9]ss(wrx-mmm).zip The zip files contain a file yrq000.dat and I don't want to overwrite them when the files are ...
0
votes
0answers
12 views

Making appointments in Calcurse without using interactive CLI interface

I'd like to make a automated script so I could enter some repeating events in Calcurse. Is there a way to do this without using the interactive interface?
1
vote
1answer
51 views

How do I add this field?

I'm trying to print the signal strength of two wifi devices connected to a hotspot. I manage to do this script that prints the ip, hostname, mac and signal. In the script below the macs are stored in $...
1
vote
0answers
41 views

Color rm -i prompt messages

I'm looking for a way to apply custom colors to messages emitted by the rm -i command: ~ $ rm -i file.txt rm: remove regular empty file 'file.txt'? I understand that I need to redirect the stderr as ...
0
votes
1answer
39 views

bash: syntax error near unexpected token `;'

I got this error bash: syntax error near unexpected token; while running this line: while; do; clear; tree .git; sleep 1; done I got this line from this video
0
votes
0answers
33 views

How to use the bash shell with Python's in place of /bin/sh

I have commands to execute in the terminal but I want to execute them directly from my python script except that my script it launches the commands on /bin /sh and my terminal on bash: just an ...
0
votes
0answers
9 views

Is it possible to make bash support UTF-8 without any locale files installed?

I have installed the bash binary into an Android device (with sh as the filename), using an app that I don't fully trust. It interprets non-ASCII Unicode characters as random control codes, or has no ...
2
votes
1answer
53 views

Run multiple commands after pipe

I am piping streamer ouput to mpv player which works fine. streamer -o - | mpv - But before starting mpv , I want to kill one program and then pipe to mpv. streamer program takes some time to ...
0
votes
3answers
38 views

MV exclude folder not working

I'm trying to copy all of the files/directories inside a folder but would like to exclude one folder as I want all the other file to be inside that folder. To better demonstrate below is the folder ...
1
vote
1answer
21 views

cp multiple files do not work in bash script

I would like to run the below command in a bash script but, it doesn't work. command: cp /tmp/first/{abc.conf,xyz.conf} /tmp/backup/ bash script: firstDir=/tmp/first #secondDir=/tmp/second ...
0
votes
1answer
26 views

Use bash EXIT trap to confirm or cancel ctrl+d [duplicate]

Is there a simple way to require confirmation before logging out of a shell, and to prevent the shell from exiting if confirmation is denied? This would be useful to avoid accidentally terminating an ...
1
vote
1answer
37 views

Unable to find regular file with default shell as bash but works when it's ksh

We have script file FileChecker.sh where it checks whether file exists or not FileChecker.sh content: #!/bin/ksh FILE=$1 FILE2=$2 if [[ "$FILE" == "" || "$FILE2" == "" ]] ; then echo "[ERROR] ...
0
votes
1answer
23 views

Parsing “mdls” output

The following script takes a user input (path to a mounted macOS volume such as /Volumes/Macintosh\ HD/) #!/bin/bash # Author: Swasti Bhushan Deb # macOS 10.13.3 # kMDItemWhereFroms.sh read -e -p "...
0
votes
3answers
45 views

how does this work ? for loop strips variable result

while learning bash/ksh from a book. i came across an exercise that had a result i would love to understand. When executing this script with bash -x to try to understand how it behaves (debugging) ...
1
vote
2answers
19 views

Function Recursion in shell

I'd like to know why this recursive function in shell works properly: exp ( ) { local result #local op1="$1" #echo $2 if [[ $2 -eq 0 ]]; then echo 1 ...
15
votes
1answer
2k views

String `!23` is replaced with `docker` in command line

I have a Maven command with the parameter: mvn test -Dcommon_password=!23foo This command is being executed as mvn test -Dcommon_password=dockerfoo I.e. !23 is being substituted with docker. Why ...
2
votes
2answers
44 views

goto a specific line in awk to start processing [on hold]

I want the awk to go to the beginning of the block of lines to start processing it again once it hit the bottom of that block and processed its last line. Basically, if block of text is <START ...
0
votes
4answers
55 views

How to extract the CSV file name from each line of this file

I have a file which contains lines like those: -rw-rw-rw 1 root root 6379 May 24 2016 test1.CSV -rw-rw-rw 1 root root 23249 May 25 2016 test2.CSV -rw-rw-rw 1 root root 2995 May 26 2016 test3.CSV ...
0
votes
2answers
50 views

Command in Linux to perform opposite of egrep?

I want to find which of the patterns or words are not present in file. Example : test.txt marco polo charlie anthony john egrep 'marco|polo' test.txt will output marco and polo But I want a ...
0
votes
1answer
27 views

Distinguishing files on the basis of first column's content

I have multiple tab-separated files with .cluster extension. I want to classify these files on the basis of their first column content using the following criteria: (2 and 3 are actual digits/content ...
7
votes
3answers
827 views

Echoing a tail command produces unexpected output?

This command, when run alone, produces the expected result (the last line of the crontab): tail -n 1 /etc/crontab However, when I run it as part of an echo command to send the result to a file, it ...
0
votes
1answer
24 views

For loop to refer a file, search for matches on the first column and print the matching rows

I have two files: File 1 an input file with 191 lines in only a column. File 2 is a master file with 712 lines in 2 columns. Output = find the match between Input_File and the first column of ...
1
vote
3answers
72 views

How can I make rm -rf ask for confirmation just once at the directory level?

If I use rm -rfi, this asks me every time each file is deleted. If I have a list of rm -rf commands, how can I make it so that the machine asks me for confirmation just once (when trying to delete the ...
0
votes
0answers
28 views

appending a text to file using cat >> is not working but echo with tee --append is working [duplicate]

I want to append the line "include /etc/nginx/tcpconf.d/*;" to the file /etc/nginx/nginx.conf. When I did run the below command, it failed - $ sudo cat "include /etc/nginx/tcpconf.d/*;" >> /...
1
vote
0answers
20 views

How do I vsync in bash (or the Linux framebuffer)?

I was trying to see how fast I could fill/swap on /dev/fb0 with something to the effect of: while :; do head -c $SIZE /dev/erg > /dev/fb0; head -c $SIZE /dev/zero > /dev/fb0; done (Where /dev/...
2
votes
1answer
40 views

search for single or multiple occurrences of the samestring and edit next line

I have a file that sometimes has one occurrence or multiple occurrences of the same string. I am needing to search for one or more occurrences in the file and go to the next line and keep the values ...
2
votes
1answer
45 views

HISTTIMEFORMAT plain doesn't work

Setting HISTTIMEFORMAT in bash to get timestamps in the history report just isn't working: > fgrep HISTTIMEFORMAT ~/.bashrc export HISTTIMEFORMAT='%m-%d-%y %T ' > bash > history | tail -20 ...
1
vote
2answers
46 views

Bash: How to delete characters from line

There is a table with data. ./result_4_0.txt ./result_4_45.txt ./result_4_45.txt ./result_4_0.txt I want to create two columns from numbers. How can I replace "./result_" "_" ".txt" just with ...
1
vote
3answers
42 views

How can I grep each file in a directory for a keyword and output the keyword and the filename it was found in?

I have a directory with 2000+ text files. I am trying to make a script that: Reads a list of IP addresses from ip.txt Cats each file in the directory Greps each file for the IP address If keyword is ...
3
votes
4answers
69 views

bash command to create array with the 10 most recent images in a dir?

I'm writing a bash script and I need to create an array with the 10 most recent image files (from new to old) in the current dir. I consider "image files" to be files with certain extensions, like ....
0
votes
2answers
38 views

creating a list of files in bash failed

I have a folder with the following file content: ls bams-lab/*.name-sorted.fixmate.sorted.dedup.sam bams-lab/OZBenth2_.fastp.fq.gz.name-sorted.fixmate.sorted.dedup.sam ... bams-lab/OZBenth7_.fastp....
-1
votes
0answers
21 views

For loop caused If 'I=…' is not a typo you can use command-not-found to lookup the package that contains it [closed]

I have the following files: ls *.dedup.sam OZBenth2_.fastp.fq.gz.name-sorted.fixmate.sorted.dedup.sam ... OZBenth7_.fastp.fq.gz.name-sorted.fixmate.sorted.dedup.sam I tried the following loop > ...
0
votes
0answers
30 views

Wait command in Bash script not acting as expected [closed]

I am making a script to play 4 different video feeds from 4 different camera DVRs via RTSP, and need them to be pretty much hands-free i.e. a dedicated mini pc running Debian that will, network ...
1
vote
1answer
48 views

Bash - How to update what's inside the quotes, but only if it's a number?

For this project, we have hundreds of applications using composer.json. I'm using a Bash script to go through and update the version numbers of any file that contain an application that is getting a ...