Stack Exchange Network

Stack Exchange network consists of 174 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.

2
votes
1answer
33 views

Cleanup Script for macOS

I have a bunch of shared Mac workstations with dozens of users. These users constantly leave large files on their desktop and in the trash, which eventually fills up the local hard drive. I want to ...
-2
votes
0answers
44 views

Whenever I open shell it print command not found [on hold]

Whenever I open a new tab or new window I see the following error in the console bash: 4e3291fa48f43adebb522c3c91f49c3120d927525994a34052bee83fb15b55f9: command not found bash: ...
2
votes
3answers
2k views

Pass output of “whereis” command to “cd” to change directory in one step

I can't find a way to pass output of whereis command to cd command in same line so I don't have to do cd in the second step. I have tried passing like below: cd $(whereis node_modules) Or cd "`...
-1
votes
0answers
47 views

brute forcer tool in bash have problem [on hold]

i coded an tool with bash script for bruteforcing one of website accounts. my code is: #!/bin/bash clear old_IFS=$IFS IFS=$'\n' lines=$(wc -l passwd.txt | cut -d " " -f1) IFS=$old_IFS linesNum=${#...
5
votes
1answer
925 views

Autocomplete issue in bash with equal sign (=)

I am trying to make autocomplete work and wroted a piece of code to demonstrate an issue I faced up: $ cat completion.sh function _completion_command() { compopt +o bashdefault +o default +o ...
0
votes
1answer
32 views

Bad substitution when running from cron

I have a function (notify_dba) that with two string args, a header and a body. (correction) Works well from shell prompt, but not in cron Err, doesn't work in either shell or cron (but should...?): ...
0
votes
1answer
21 views

Renaming Multiple files in different directories

I have about 5TB of data stored on Synology NAS servers with a DSM of 6.1+, so bash should be available for use on these systems. The issue is that we are currently archiving this data to external ...
0
votes
0answers
21 views

How can I regex match-and-replace _all_ on-screen text?

I need a way to replace an on-screen pattern with another string, regardless of what places that text on the screen. Maybe I can live without user input being replaced, but anything that comes from ...
16
votes
5answers
10k views

How can I recall a numbered history command for edit?

I frequently search for changes with history | grep 'string' I get a list of commands in my history, along with the history line number), e.g. history | grep 'git' 755 git status 1535 git push ...
0
votes
4answers
56 views

Get the command that generated piped data

I'd like to figure out a way to access a string describing the command that was run before the current command running. For example, if I run: ls | myscripthere I'd like to be able to know that the ...
3
votes
1answer
410 views

Display git branch in terminal

I am using fedora OS and I want to display git branch or tag in terminal when I go into the git folder project. I follow this tutorial. After I ran: source /usr/share/git-core/contrib/completion/git-...
0
votes
2answers
28 views

Copy a folder overwriting ONLY smaller files in destination

I have tons of PDFs in multiple sub-folders in /home/user/original that I have compressed using ghostscript pdfwrite in /home/user/compressed. ghostscript has done a great job at compressing about 90% ...
12
votes
3answers
35k views

How to use grep when file does not contain the string

In my bash script I'm trying to print a line if a certain string does not exist in a file. if grep -q "$user2" /etc/passwd; then echo "User does exist!!" This is how I wrote it if I wanted the ...
0
votes
5answers
73 views

How to separate each line of text by comma and put them in an array?

I have a text file and I want to create an array out of it like this: array=["line1","line2",...]. Here are the first lines of my text: Hamlet William Shakespeare Edited Barbara B Mowat Paul ...
-1
votes
0answers
25 views

How to capture a terminal command and replace by another one?

I want to redirect the user's command line, to copy another folder when they tried to git clone content from a specific folder. For example: git clone https://github.com/delivery.git john_copy I ...
3
votes
1answer
43 views

How to run script at start when everything is up and running?

I have a PC for routing purposes, it has 2 network interfaces and runs Debian. I want to add a sound to it, to signal that it is booted and okay. So I've created some /etc/init.s/beep-startup script, ...
7
votes
3answers
332 views

Is “Arithmetic Expansion” the expected action on vars inside `[[` tests?

This script: a=2 [[ "$a" -eq 2 ]] && echo yes1 [[ $a -eq 2 ]] && echo yes2 [[ a -eq 2 ]] && echo yes3 [[ "a" -eq 2 ]] && echo yes4 Does not work in dash (and ...
9
votes
1answer
362 views

Usage of enclosing braces {} as arguments to commands and their options

Examples I've recently found examples of using pairs of enclosing braces {}, with nothing in between the opening and closing braces, as arguments to commands and even to their options: cat foo | ...
1
vote
1answer
1k views

Add 5 minutes to date in bash

I've seen that the "date" command can do powerful manipulation of timestamps, but I'm not quite getting it to work right. Can anyone help explain the output below, and suggest how I could get the ...
0
votes
1answer
29 views

[1]+ Exit 125 nohup [on hold]

I am running the following command: nohup ./run_hyper_param_tuning.sh> ../../logs/hyper_model_15_b_Jan.txt 2>&1 & echo $! >save_pid.txt It has been always working but suddenly it ...
121
votes
2answers
20k views

When was the shellshock (CVE-2014-6271/7169) bug introduced, and what is the patch that fully fixes it?

Some context about the bug: CVE-2014-6271 Bash supports exporting not just shell variables, but also shell functions to other bash instances, via the process environment to (indirect) child ...
0
votes
1answer
63 views

BASH logic problem; difficulty testing one string variable with IF and OR

I have a string var1 which I am using in BASH. It can be three values var1=on var1=off or var1 can be equal to anything that is not on or off I wish to build an if statement in BASH that tests $...
1
vote
1answer
21 views

Can I create BASH function that will hold text block that can then be called for output to FILE and SCREEN to cut down on code block repetition [duplicate]

I have a BASH utility that outputs measurements to screen live as it runs and writes the result to file at the same time. I am having to repeat the same code twice (see below). Once to write to ...
0
votes
0answers
20 views

Get output of server crash from server re-spawning script

I currently have Homebridge set up on my raspberry pi. When the pi boots, it starts a script which attempts to keep homebridge alive. I originally took the script from this answer which walks you ...
4
votes
2answers
324 views

Find only GUIDs in file - Bash

I have a file that might contain GUIDs (their canonical textual representation). I want to do an action for each GUID in the file. It might contain any number of GUIDs. I have already a file ready ...
6
votes
1answer
305 views

Is there a difference between cmd_drain < <(cmd_src) and cmd_drain <<< “$(cmd_src)”?

The cmd | read -r var1 var2 construct famously does not work in bash because the read command is executed in a subshell due to piping. I used to use read -r var1 var2 <<< "$(cmd)" to get ...
0
votes
1answer
1k views

use EOF in a one-liner?

I have a simple script that executes commands on remote host using ssh and EOF I was trying to do it with a one-liner at command line but I couldn't figure out how to do the EOF outside of a script. ...
0
votes
3answers
28 views

How to escape parenthesis in bash rmdir?

I have a directory that has a name like 10.2 (14C92) i want to remove using rmdir -rf (to include their content). I am very new to the linux command line so i do know how to pass a space with \ but I ...
1
vote
2answers
35 views

bash: declare/typeset without assignment appears to fail

Using bash 4.3, there seems to be a discrepancy between the manual and actual behaviour: unset string # just to be sure declare string # $? is 0 afterwards declare -p string # fails, 'string: not ...
1
vote
1answer
1k views

How to invoke shell function in string? (bash)

I want to invoke shell function in string. Here is my use case: function envfoo() { env ENV_FOO=foo $@ } function envbar() { env ENV_BAR=bar $@ } $ envfoo env |egrep ENV_ ENV_FOO=foo $ ...
1
vote
1answer
62 views

Translate BATCH to Bash

Hello Unix & Linux Community, I am here to ask how I can translate a Windows Batch File (.bat), into a Linux Bash File (.sh), because I want to allow a program I made, into Linux. But I have no ...
-6
votes
1answer
46 views

bash loop all files in directory, then loop lines of each file

I have urls1.txt urls2.txt urls3.txt And so on. How can I loop all files in this directory then loop each line of these files?
57
votes
7answers
168k views

How to read first and last line from cat output?

I have text file. Task - get first and last line from file after $ cat file | grep -E "1|2|3|4" | commandtoprint $ cat file 1 2 3 4 5 Need this without cat output (only 1 and 5). ~$ cat file | ...
1
vote
2answers
34 views

Error while trying to compress pdf using ghostscript recursively via loop

I intend to compress a few thousand PDF files in a folder recursively. I tried with following loop: #!/bin/bash find "/home/user/original" -type f -name *.pdf | while read -r file do gs -sDEVICE=...
0
votes
3answers
263 views

Bash script with limited path

I'm trying to write my first bash script to essentially install a bunch of dependencies and then execute a script. I'm struggling debugging this with the user b/c I'm a dev which means I already have ...
1
vote
1answer
24 views

No nohup logs on remote server

I'm trying to start a proccess on remote server with ssh. I need to log stdout on target server (not the local one) Here is the script: sshpass -p mypwd ssh root@myserver.com nohup java -jar /tmp/...
1
vote
2answers
27 views

Speeding up repeated python calls (or, alternatively, porting a complex regex to sed)

I am an academic medical physicist. I do experiments that generate a fair amount of data, and they are expensive to run. My university has a backup system that consists of a robot tape library in a ...
0
votes
1answer
20 views

Reading multiple files and operating on stored Arrays

I have 2 text files "${LinkP}" and "${QuestionP}. I want to read these files and store each complete line in the respective array, IFS=$'\r\n' GLOBIGNORE='*' command eval "LinkA=($(cat "${LinkP}"))" ...
-1
votes
0answers
55 views

Automate forcibly closing open files that have been deleted already by a misbehaving application [on hold]

On our Hadoop cluster, we have an application that opens and deletes files, but never closes those files. As this has a performance impact, we're now manually closing those deleted files by using gdb....
1
vote
1answer
82 views

'revert' bash to searching correct history file [closed]

I recently decided it would be a good idea to start backing up my history, and did so with the following added to .bashrc: export HISTFILE=~/.history/`date +%Y%m%d`.hist export HISTSIZE=100000 No ...
0
votes
3answers
53 views

How do I generate a sequence of numbers like this?

I am trying to generate a sequence of numbers where it adds 1 every other time, and 39999 every other time. Example of list which does what I want up to a million: 1 40000 40001 80000 80001 120000 ...
0
votes
2answers
458 views

Bash syntax error when `cd`ing into directory

**So, after doing a little digging, I got it to work. You do get far enough in the install using WINE for this to work properly. Here are the steps: Open the shell, and type in cd .wine cd ...
3
votes
3answers
2k views

bash script that reads user input and uses “cal” command to validate dates

I want to write a script that reads my input (for example if my script is called "check", then I would type "check 9 4 1993" and that input would go through the cal command and will check through the ...
1
vote
4answers
129 views

Floating point numbers in bash [duplicate]

Let's say I have a variable and I want to print 5 significant digits after I multiplied it by 1000. zsh can do it: zsh$ x=2.8026407e+00 zsh$ printf "%.5g\n" "$(( 1000*${x} ))" zsh> 2802.6 Can ...
6
votes
2answers
909 views

* at end of directory path

I have a question about the * character at the end of a directory path in a bash script. I have a script that's supposed to automatically delete some archives from a server once they get old enough. ...
2
votes
2answers
4k views

Script to create files in a template

I just wrote a function in my ~/.bashrc that will let me create a folder for a new website with one command. The function looks like this: function newsite() { mkcd "$*" # mkdir and cd into it ...
1
vote
1answer
24 views

Define variable using read from stdin of heredoc

I am trying to store Available and Total Memory into variables in a script file as follows, read -r Available Total <<EOT $(free -m | awk '/^Mem/{print $7; print $2;}') EOT $ echo $Total $ ...
0
votes
0answers
27 views

After SSH not able to read the input from the keyboard and display on the screen

#!/bin/bash server=(*.*.*.*) echo "Connecting to IP : $server" ssh -i dotestnet root@${server} " echo "Present Working Directory : $pwd" echo "Deleting existing packages...." rm -rf ~/transactions rm -...
0
votes
3answers
378 views

Variable inside a variable in a loop

I have a question regarding how a variable can be called with another variable name inside a loop. The following script does not work: #!/bin/bash # Comparing test1.txt with test2.txt, test1.ini ...
44
votes
9answers
69k views

Terminating an infinite loop

I have a command that I want to have run again automatically each time it terminates, so I ran something like this: while [ 1 ]; do COMMAND; done; but if I can't stop the loop with Ctrl-c as that ...