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.

0
votes
1answer
16 views

control-flowed variable in Bash

The web-application document-root for Debian-Apache is typically /var/www/html/ but for Arch-Apache it's typically /srv/http/. I wrote a distro-agnostic LAMP-establishment script and I need it to ...
4
votes
1answer
27 views

Why bash “read -t 0” does not see input?

My script (should) acts differently, depending on the presence of the data in the input stream. So I can invoke it like this: $ my-script.sh or: $ my-script.sh <<-MARK Data comes... .....
-2
votes
1answer
25 views

my question is based on bash script on files

what is the bash script to divide input files which has name end with string"out_root" and script should take input file name and number of output files and number of output files generated should ...
1
vote
1answer
16 views

how to pipe to a sourced function in bashrc file?

we all know how to pipe to shell scripts and installed programs like grep,awk ... but what about a sourced function in .bashrc or .zshrc ? this is a test function : function fff(){ echo "$@" } ...
12
votes
2answers
589 views

What is the difference between the commands builtin cd and cd?

I encountered a Linux command, builtin cd. What is the difference between the commands builtin cd and cd? In fact, I made some researches about the difference, but I could not find a remarkable and ...
1
vote
1answer
22 views

collect logs from bash each 24 hours [on hold]

my idea is to collect logs each 24 hours ,mail it and flush them after that i wrote some scatch for example 1.var/log/auth {some info} 2.var/log/something.log {some info} list="$(find /var/log -...
3
votes
4answers
56 views

Why does `… | sed 's/^/stdout: /'` print on empty stdin when `… > >(sed 's/^/stdout: /')` doesn't?

I'm trying to understand what causes the difference in these 2 constructs that I thought were functionally equivalent: $ ( echo foo >&2 ) 2> >(sed 's/^/stderr: /') | sed 's/^/stdout: /' ...
1
vote
2answers
41 views

Everything should be run in background instead of waiting

I have written a script that takes commands from user and runs through a huge list of servers and writes to a single file. Once writing has completed it triggers an email. My requirement is: the ...
4
votes
3answers
60 views

Define bash function which does not show up in xtrace (set -x)

In a bash script I have a log() function that is used in several places, as well as a logs() function that diverts lots of line to log(). When I run parts of the script with set -x, obviously all ...
0
votes
2answers
75 views

Creating a temporary file from standard input

Say I have a standard input stream of file contents and a command that expects a file name as an argument and I want to run that command on a file made up of the standard input stream’s file contents. ...
0
votes
1answer
29 views

When does the loop starting with while [ -n “$1” ]; executes?

I have a shell script with while loop starting with while [ -n "$1" ]; do I know that $1 refers to the argument right after the name of the script, ie firstargument, when I execute ./myscript.sh ...
-1
votes
1answer
24 views

script calling another script?

ive written a couple a couple of scripts. are they going to work indefinatly and will them eventually overload the CPU? firstly this is on a local nas that for some reason the manufacturer does not ...
0
votes
1answer
27 views

bash script split file names

I have the following bash script: #!/bin/bash for r in $(find . -name "*.fastq"); do cat <<EOF #qsub <<EOF #!/bin/bash -l #PBS -N $r EOF done Unfortunately, all filename get ...
2
votes
2answers
68 views

import environment variables in a bash script

I set some environment variables in a terminal, and then run my script. How can I pull in the variables in the script? I need to know their values. Simply referring to them as $MY_VAR1 doesn't work; ...
4
votes
2answers
325 views

The files with the extension bash and sh

I made some researches about the files with bash and sh extensions. Most of the people and resources say that if a file has bash extension, then it contains bash scripts. Likewise, the file with sh ...
1
vote
1answer
42 views

How can I source a base 64 encoded file in bash?

Is there a way to source a base64 encoded file in bash instead of doing this? cat $DIR/data/saves/$savegame | base64 --decode > $DIR/data/saves/$savegame.decoded . $DIR/data/saves/$savegame....
0
votes
1answer
30 views

Visible content of 2 variables in bash is the same, but the length is different

These 2 variables will have the same visible content x_sign1="aabbccdd_and_somthing_else" var1="...." [........] x_sign2=$(echo -n "${var1}${var2}${var3}" | shasum -a 256) echo $x_sign2 ...
0
votes
1answer
21 views

Maintaining several constants for several bash scripts

I have several individual bash scripts. They do different things, and are large (70-100 lines each). Thus I have kept them in separate files. But they are all related to a central problem and hence ...
0
votes
2answers
43 views

Bash array script, combine

I'm trying to write bash script, which will automatically read all file names in current and custom directories, then apply new created docker image' names to finded yml files via kubectl, then read ...
0
votes
1answer
21 views

How to implement returning to top level menu?

I have a complex menu driven program along the following lines: echo "Navigate through the following choices when you get the #? prompt: " options=("Action 1" "Action 2" ...) select $opt in "${...
1
vote
1answer
35 views

Generating a report from bash output

I am currently trying to write a script in Bash that can run a set of unit/integration tests. I have that part working, but what I need now is to be able to output a summary at the end. I have been ...
-1
votes
4answers
58 views

SQL operation on csv file using bash or shell

This is my input file 0164318,001449,001452,001922 0164318,001456,001457,001922 0842179,002115,002118,001485 0846354,001512,001513,001590 0841422,001221,001224,001860 0841422,001227,...
0
votes
1answer
35 views

Bash script to move through folders, unzip, and move files up one directory

I have a group of folders that all have zip files in them that may contain 1 or 2 files in them each in a new folder. (see diagram below) I want to point the script at the top level directory and ...
2
votes
1answer
53 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 ...
0
votes
1answer
28 views

Renaming Multiple files in different directories [duplicate]

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
1answer
52 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
0answers
25 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 ...
-2
votes
0answers
47 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: ...
-1
votes
0answers
27 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 ...
1
vote
2answers
47 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% ...
3
votes
1answer
48 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, ...
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 ...
0
votes
1answer
31 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 ...
-3
votes
0answers
66 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=${#...
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
5answers
78 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 ...
6
votes
1answer
317 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
3answers
30 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 ...
0
votes
0answers
21 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
328 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 ...
10
votes
1answer
392 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 | ...
-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?
1
vote
2answers
37 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
1answer
67 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
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/...
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
vote
3answers
61 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
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 -...
1
vote
1answer
25 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 $ ...
2
votes
2answers
22 views

can bash show one array item id and value using `declare -p`?

$ str="a'\"b" $ declare -p str declare -- str="a'\"b" # see " was escaped, possibly other chars will too $ astr=("$str" "c") $ declare -p astr declare -ax astr='([0]="a'\''\"b" [1]="c")' so, is there ...