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
18 views

How to capture all std outputs [duplicate]

Suppose I have a program called mktemp which creates a random tmp directory in /tmp and also produces a string output of the directory address Input[0]: mktemp Output[0]: /tmp/tmp.MkrKAscwwk How can ...
0
votes
0answers
21 views

How can I catch command status code and throw error before tee?

I want to catch (and throw error) before tee command. #!/usr/bin/env bash set -xe serverless | tee /tmp/output.txt However serverless command fails, tee returns non-error status code. How can I ...
1
vote
2answers
50 views

Why do I need 'exec' if 'while read' can open a 'File Descriptor'

I want to read a file line by line using bash, tail and using a diferent file descriptor. all the guides use this method: method 1: echo 1111111 > z.txt exec {newFD}< <(tail -f -c +0 "z.txt"...
0
votes
1answer
28 views

adding contents with multiple files using awk, sed or grep

I have to files named file 1 and filed 2 following format: file 1 with 18000 lines COL1 COL2 COL3 COL4 COL5 - . ID = tom_fa_10005086 - 0 Parent = tom_fa_10005086 - 0 Parent = ...
-1
votes
1answer
17 views

How can i check if a number is higher or lower then another number?

I have files that contain 2 numbers like the following: File 1 1 0 File 2 0 1 File 3 3 3 I want to compare the number on the first line to the number on the second line. If the number on the ...
-1
votes
2answers
21 views

Identifying shell script's subshell number from within a script itself

I am accidentally caught in a desire to reveal the subshell number (BASH_SUBSHELL) from within the script itself, but i get subshell 0 Here is the script's line echo "Operated from subshell: $...
0
votes
2answers
32 views

Renaming files with the same name when moving them

This is my current code: Base_DIR=/file/path other= /folder/path find "Base_DIR" -type f -name "*.txt" while IFS= read -r file; do year="$(date -d "$(stat -c %y "$file")" +%Y month="$(date -d "$(stat ...
0
votes
1answer
22 views

Rename Root folder directory - I've managed to rename folder structure to my name by mistake

Using Kali Linux and somehow managed to rename a folder in the structure: root:/bin/bash/myName So my question is how can I rename the myName folder? as I would like to set up a new user profile ...
0
votes
1answer
17 views

Parsing folder structure with $HOME in the name

So I am a making a simple backup script, it will be run every hour. All this script does, is make a backup directory and copy files: ./backup/'$HOME'/Documents/todo.txt backup structure - backup ...
1
vote
1answer
39 views

Prevent dangerous commands from going into bash history

What's the easiest way to prevent dangerous commands matching a pattern (like rm) from going into the Bash command history? I'd like to keep them away from the history of the current session, not just ...
0
votes
0answers
42 views

How to pass to ssh the key stored in a shell environment variable?

Presumably ssh tries to access the fd several times, but the fd is destroyed after it has been read the very first time: # ssh -i <(echo $KEY) user@example.com Warning: Identity file /dev/fd/11 ...
-1
votes
0answers
18 views

Start a screen with minecraft server after restart?

I am trying to have a minecraft server auto start on a screen after the server reboot. Currently using CentOS 7. Here's my minecraft.service i put in systemd. [Unit] Description=Start Minecraft After=...
6
votes
2answers
676 views

How to produce a PS1 prompt in bash or ksh93 similar to tcsh

In tcsh, I have the default: prompt [%m:%c3] %n%# which gives prompts like: [woehler:hacking/c/hello] ajcarr% and [woehler:~] ajcarr% In other words, the current directory and up to the next ...
-1
votes
1answer
52 views

How can i terminate 'find' after the first match?

I am using find in a while loop. it takes a list of ips in ip.txt, searches for the ip in a directory of files and then writes the name of the file that each IP was found in to a file called results....
0
votes
1answer
35 views

Looping through two files with a for loop and evaluating the indices

I am learning bash shell scripting and am looking for pure bash ways rather than awk, etc. I am trying to use a for loop to go through the contents of two files that are submitted as arguments in the ...
2
votes
2answers
26 views

JQ Linux JSON Parse Unknown Key

I have a problem: I want to build an automated script which builds an new VPS Server on the page vultr.com. They also have an API Access and I could create it and receive also anything I need. The ...
0
votes
0answers
8 views

Why is this Thunar Custom Actions Pastebin script posting with unwanted quotes?

This question is regarding these nice thunar custom actions scripts which I found here: https://github.com/cytopia/thunar-custom-actions One in particular is doing something strange that I can't seem ...
0
votes
0answers
11 views

macOS High Sierra “log show ” ouput

The log show command output from a macOS High Sierra is detailed below: **Command 1** log show --info --predicate 'eventMessage contains "system boot:"' log: warning: ./system_logs.logarchive ...
1
vote
1answer
54 views

writing a script that finds incorrect files, and corrects them through stdout

I am currently using UNIX bash, and I want to write shell script that allows me to correct the date entry by using information in a file's pathname. Background: I previously had 200 files that were ...
1
vote
2answers
45 views

Regain ability to use ^C to close backgrounded then (effectively) foregrounded processes

In the interactive console, pressing ^C on zenity --info & fg closes the Zenity window. One can only use zenity --info & wait in a script. But ^C doesn't close the Zenity window in this case. ...
1
vote
0answers
27 views

!$ vs $_ difference? [duplicate]

In GNU Bash, both !$ and $_ expands to the last argument of the last command. I think they're identical and I need someone to tell me if there is any difference.
0
votes
1answer
23 views

Exported Date Variable not appearing in subshell

I'm currently working on creating 2 bashes with two different scripts which result in two files named with the same timestamp for easy comparison/processing later. The date variable gets created in ...
8
votes
3answers
327 views

How can I list files in reverse time order by a command and pass them as arguments to another command?

I have a program which takes in some files as arguments in one command line. I would like to invoke it with all the files in a directory listed in reverse time order. For example: I have following ...
1
vote
1answer
26 views

Modify bash history from inside subshell in an interactive session

I executed history > before; (history -d $n); history > after where $n is the number corresponding to the last command I typed in the same interactive session before executing this line, The ...
0
votes
0answers
10 views

How to validate pbrun working or not but not really doing pbrun

I am developing and health check script for our application and we need to validate few things after every major change and/or patching . One of the checks is whether the pbrun access is working or ...
1
vote
1answer
49 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
67 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
vote
1answer
35 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?
2
votes
2answers
58 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
16 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
25 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
19 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
25 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
22 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
48 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
34 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
25 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
13 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
54 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
44 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
40 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
55 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
39 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
22 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 ...