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.

0
votes
2answers
39 views

Append string on redirect

When redirecting all output to stderr: stat file >&2 ... if the command throws an error (e.g. file does not exist) how can one prepend some arbitrary text, such as: <<MY ARBITRARY TEXT&...
0
votes
2answers
43 views

Parse config file and pass parameters to another script

I have a config file containing the following: variable1 = 25 variable2 = 36 I want to parse this file in a Bash script and set each respective variable to its proper value within my script. How do ...
0
votes
0answers
23 views

running bash script from cron job not working properly

I have the following script: #!/bin/bash echo "$(date +"%r")" if [ "$FOLDER_ID" != "0" ] then node /sync.js -d $FOLDER_ID -l /Downloads fi I'm using docker container and I have passed the env ...
-1
votes
1answer
57 views

Bash Script Wind Chill using getopt and bc

I am now getting the correct output, however it is not scaling to only 3 places. Anyone know how to do that? function windchill { to=32 v=10 vel=`echo 'e(l('$v')*0.16)' | bc -l` w=$(...
0
votes
1answer
22 views

searching/showing size of files

is there an easy way to look through a directory and say, for every file that starts with a-z, print the total size of those files? for example for i in {97..122}; du (something); done i.e output>>...
0
votes
1answer
33 views

sudo redirection doesn't work when in a function

I have a script which writes some content into a file with cat and EOF. While this thing works within a bash script, it doesn't work if I put it inside a function. Working code: cat << EOF | ...
0
votes
1answer
23 views

Bash Scripting: How to check for active sshfs mount in dir?

If currently have this code: 0130: moba(){ 0131: if [ -z "$(ls -A /home/me/Documents/A/B)" ]; then 0132: echo "Empty" 0133: sshfs me@domain:/home/C/D /home/me/Documents/A/B/ 0134: ...
-1
votes
2answers
45 views

How to batch rename files in folder [closed]

I have a zip file where each file is named the following original.jpg.1.png original.jpg.2.png The files are actually jpegs How do I go about renaming them to the following? original1.jpg original2....
0
votes
2answers
49 views

Print SSH loop output Column wise

I want to print output of below loop into columns, Can anybody please adivse me on this. #!/bin/bash DATE=`date "+%d-%m-%Y_%H-%M-%S"` ### Find User from Server with Expiry Date for i in `cat /home/...
0
votes
1answer
65 views

Regex expression for IP address/CIDR in bash

I want to check if the user input is a valid IP address/CIDR in bash and I am using regular expressions to do that. So valid CIDR should be 0-32 and for IP from (1-254).(1-255).(1-255).(1-255)/(1-32) ...
0
votes
1answer
36 views

Total Progress over entire bash shell script

EDIT FOR CLARITY : say I have the following script (let's posit pv and curl are already installed) : (that currently runs under ubuntu but that I plan to make POSIX-compliant so that it may run on ...
0
votes
2answers
36 views

how do i add the creation of a directory to this cli command

I'm traversing a directory, looking for subdirectories, finding certain files, and copying them someplace else... I'm doing this: for i in `ls ./*/filename`; do cp $i ../test2; done This takes all ...
0
votes
0answers
35 views

Spell-checker for an interactive bash on Debian as Ubuntu?

I'm not sure, but I remember Ubuntu can do similar to: $ miswrite-command No 'miswrite-command' found, did you mean: 'correct-command' from 'correct-package' (main) Try : sudo apt install ...
0
votes
0answers
30 views

Using unusual paths with commands

Assuming one has the following directory: mkdir """ '''\n " And one queries the directory with: stat --printf '%n' ** #or for simplicity stat --printf '%n' $'\n'\'\'\'\\n$'\n' And captures the ...
0
votes
1answer
29 views

sudo in bash script: Doesn't always wait for password

I have a simple bash script like this: #!/usr/bin/env bash sudo ./some_other_script_01 sudo ./some_other_script_02 When I execute this script, I always see the password prompt, as usual: [sudo] ...
0
votes
2answers
31 views

Bash not appending array to new index. Just extends first index

I am using arrays in bash and one particular array is behaving unusually. I am using a function and calling an external script which returns a value to be appended to an array as follows: function ...
0
votes
0answers
14 views

New processes in Bash script [duplicate]

How do you create new processes in bash shell script? I have seen people saying to use fork(), but I’m not sure how to do that in a shell script.
0
votes
3answers
41 views

How to prevent parameter expansion around a variable I want to be resolved?

Edit: Important note before reading further: since Kusalananda's anwser, my question is now quite useless, since he pointed out a bug in another script I used. Now this bug is fixed, the below errors ...
1
vote
0answers
66 views

How does 'Open with' a custom executable in Linux work?

I have a file called foo.txt. I want to associate my own program with the mime-type .txt so that my program opens a terminal and shows the contents of foo.txt as standard output. I would prefer Ruby, ...
2
votes
1answer
19 views

Pass parameter to Bash function which will serve as a pattern to awk [duplicate]

I would like to know how to pass a argument to a Bash function which would consequently serve as a pattern to awk. I have read several Q/As which tend to answer the same question, however, I am ...
0
votes
1answer
27 views

Understanding $() (and for-loops) in bash

I have a directory with git inside and git branch gives me the following output: $ git branch branch1 * branch2 master The * marks the current branch. I would like to use this output in a script....
1
vote
1answer
38 views

Inject string in tee output

I am using pipelines to implement some functionality with bash on Centos 6. During these pipes I want to export my data in a log file, but this data comes from different pipes in my pipeline and I ...
0
votes
3answers
37 views

How to check if a a variable contains both alphabets and numbers

I am trying to make a check in a shell script on linux which exits if STR contains "only alphabets" or contains "only numbers". it should pass if STR contains both numbers and alphabets. And not ...
0
votes
1answer
20 views

Compare between two bash arrays inside docker

I need two make a new bash array, not including elements which are in second one. And then use this array in while loop: while [ -n "${ids_toproc[0]}" ] ; do Here is a code a implemented: all_ids=( ...
0
votes
2answers
61 views

What is Linux exit status and list of all status

I'm trying to learn Linux bash scripting and I'm read through the articles in the http://tldp.org sites I saw some kind log clearing scripting I notice that something is used for as an exit status. I ...
-1
votes
1answer
19 views

How to clone multiple repositories from different project using shell script?

I had an url for multiple projects inside i have multiple repos for each project I need to clone all the repos in a directory and find git branches. i tried this #!/bin/bash project=(aa bb cc) aa=(...
0
votes
1answer
78 views

-bash: ./catalina.sh: No such file or directory

Using SSH, I want to execute catalina.sh to start a Tomcat server (from my client Mac terminal). I log in without any issue. Then, I do: [site /home/public]$ cd $CATALINA_HOME/bin and on Enter I ...
0
votes
2answers
32 views

How to directly compress CURL output as named archive entry?

I've hundred of text files I need to CURL from remote host. Currently I've a loop which download each file and then compress it as new .zip entry. Is it possible to directly pipe CURL's output to an ...
1
vote
2answers
73 views

How to pass strange path arguments to commands [closed]

I'm sending commands via stdin, how can I send path arguments in a safe manner? E.g. stat /some strange/p"at\nh'/ fails because of the strange path. Could path be stored in a variable or other ...
-5
votes
1answer
46 views

what is the meaning of the following shell option - shopt -s nullglob extglob [duplicate]

we have bash -version GNU bash, version 4.2.46(1)-release (x86_64-redhat-linux-gnu) what is the meaning of the following shell option ( in bash script ) shopt -s nullglob extglob and what is the ...
0
votes
1answer
42 views

Print all variables used within a bash script

Is there any way to print all the variables declared and used within a Bash script? For example printf "%s\n" "${FUNCNAME[@]}" will print the names of all shell functions currently in the execution ...
0
votes
1answer
29 views

How to detect line break and non-space character in bash case logic?

I'm writing a bash script and using the case logic to detect if my $message has non-space character, but I also want to detect non-line-break as well. Sometimes my script has the $message variable ...
2
votes
0answers
66 views

Legitimate reasons for a program to intercept, internally handle and ignore SIGINT signal

We know that - aside from SIGKILL and SIGSTOP - a program can intercept IPC signals, and run its internal handler circumventing the operation of the default handler. I can think of at least one very ...
0
votes
1answer
22 views

How to add both date and space to a filename [duplicate]

If I execute touch $(date '+%F %T'), I expect one file whose filename comprises the date and time to be created; but instead two files are created: one whose name is the date, and the other whose name ...
0
votes
2answers
41 views

line 7: [: missing `]' I have that error How do I fix it? I have indented [duplicate]

#!/bin/bash until ["$userIn" = "j"] do echo "Welcome to the Menu_Script Program!" echo echo "Menu Options" echo "Please Select an Option." ...
3
votes
2answers
444 views

How to count words in a line

I have a text file called "shoplist.txt" which one have: drinks water cola fanta fruit banana orange And I want to get how many items per line I have. I'm able to extract drinks and fruit with ...
0
votes
2answers
64 views

Replace User Name on one file with User Name plus Company from output of another file

I have 2 text files. One is the list of user names along with the company they work on the same line but separated by a tab space. The second is a output from a weekly generated report that includes ...
2
votes
1answer
20 views

Alert or execute script, only if config file shows not in production mode

I would like to test the software in development by running a particular script, say script file.ext. But I was told that I an not allowed to run the script if a config file, say file.conf, contains a ...
0
votes
1answer
47 views

How to create a 7zip archive of files from a directory, excluding existing archives?

Want to 7zip all files in root/current folder except for all zip-files AND all 7z/7zip files. I can only get one of these to work at a time in one if ! statement: for file in ./test2/* do if ! { ...
0
votes
0answers
31 views

Bash - find certain files and remux with ffmpeg then delete the old one

i just would like to use this command: for i in *.ts; do ffmpeg -i "$i" -c:a aac -b:a 128k -c:v copy -crf 20 "${i%.ts}.mp4"; done but only for a specific files like: above 350 000KB size or created ...
5
votes
1answer
421 views

Unexpected behavior of Bash script: First executes function, afterwards executes alias

When I execute the following script #!/usr/bin/env bash main() { shopt -s expand_aliases alias Hi='echo "Hi from alias"' Hi # Should Execute the alias \Hi # Should Execute the ...
0
votes
0answers
24 views

Background processes in bash preserving order

From a GUI terminal emulator running bash, I would like to open a tabbed instance, get its X window ID, and use it to embed four st terminal instances inside tabbed, with titles from 1 to 4, in ...
0
votes
1answer
68 views

Login loop, bash: cannot create temp file for here-document: No space left on device

I'm trying to login to my elementaryOS and i stuck in a loop(i enter password, press enter and it back to login). I entered the terminal (ctrl+alt+f3) to see what's going on with permissions, and i ...
1
vote
2answers
31 views

How can one stat an entire directory using a single command line starting with bash -c?

How can one stat an entire directory using a single command line starting with bash -c? This returns all files except for those prefixed with . bash -c "stat /path/todir/**" This returns all files ...
0
votes
1answer
36 views

“$PATH” being exported as literally “$PATH” [closed]

So in a bash_config profile I have export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk export JAVA_PATH=$JAVA_HOME export PATH=$PATH:$JAVA_HOME/bin But rather than appending the PATH it is setting it ...
2
votes
2answers
54 views

How do I replace words with increasing numbers?

For example, the only thing in file.txt looks like this: xxxxxxxxxHAHAxxxxxxHOHOxxxxxxx I hope to replace HAHA with seq 1 3 and replace HOHO with seq 5 7, so the output should be: ...
2
votes
1answer
33 views

su: What does the hyphen with nothing immediately following it mean?

Written as if it were an option, e.g: > su - someuser Don’t the space breaks apart “-“ and “someuser”? I went through the manpage but didn’t notice an entry for it.
1
vote
3answers
71 views

grep can't get the word I need, but Linux continues to do the next job. How do I stop it?

I have quite a few txt files. They contain the word 'Minimum' (it only shows once in each file), and I want to get the line that contains this word, and show the line in a new file. To do this, I use ...
6
votes
2answers
94 views

Emit zero-width bash prompt sequence from external binary

In bash, how do I encode zero-width sequences into PS1, when those sequences are coming from stdout of an external process or function? How do I implement writes-prompt-sequences-to-stdout so that it ...
0
votes
0answers
36 views

How to write Docker logs to a file in real time (à la `tail -f`)

I docker that output logs stdout stderr, which can be viewed using: docker logs -f $LOGS_CONTAINER_ID I also added 'sed', which puts the container id on each line: docker logs -f $LOGS_CONTAINER_ID ...