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
0answers
5 views

Getting the audio-playtime of a folder from the command line

Is there a way/tool for the linux command-line (bash) to get the overall audio playtime of a certain directory? Something like: playtime --all --recursive /Music/DrumAndBass/ output: 1:35:06
2
votes
1answer
100 views

nesting brace expansion and command substitution

I want to create a simple bash-script that checks whether a directory contains all the files whose names contain numbers from 1 to N. # Creating some files for testing $ cd /tmp/ $ mkdir test $ touch ...
0
votes
1answer
27 views

bash share array in “for do () & wait” loop

I have an issue with the script below. It uses a few sql statements in a for loop to set variables and produces a log file. The current db produces +- 1200 lines of output. The original version is ...
1
vote
2answers
32 views

assign output of command to array

when i run this command: cat output | grep -i state | sort | uniq | awk '{print $ 3}') the output is: 00x1 00x5 0080 to aasign them to an array i did this: STATUS_ARRAY=($(cat output | grep -i state | ...
0
votes
0answers
37 views

Unexpected value of $? when using subshell

I want to check if a file exists in HDFS or not and capture it in the variable SUCCESS_FILE_CHECK, i.e., if file exists the SUCCESS_FILE_CHECK should be 0 else it can be any other value. $ ...
0
votes
1answer
10 views

Comparing the `time_total` of two curl requests to different sites

I know that I can get the time_total of of curl request by using this command: curl https://www.google.com -s -o /dev/null -w "%{time_total}\n" Is there any way for me to easily compare the results ...
0
votes
1answer
29 views

Shell script which returns elapsed time, memory usage and CPU usage of executed script

I need to write a bash script which will be able to return elapsed time, RAM usage and CPU usage of executed script. my script: #!/bin/bash STARTTIME=$(date +%s%N) #here is script which needs to be ...
1
vote
1answer
30 views

Get container directory more easily

I have a bash script here: $GOPATH/ src/ build.sh and in build.sh I have: export GOPATH="$(cd $(dirname "$BASH_SOURCE") && pwd)" is there a shorter way to get the containing dir ...
2
votes
1answer
52 views

Change the shell of vim

I change my shell to zsh now.But when I call shell in vim by :! xxx will call the bash.So, how can I call zsh in vim ?
-2
votes
0answers
20 views

bash script to change lines in .cc file [on hold]

I need to create a script that can access specific variables in a .cc file and update their values. Can anyone send me any link that has info on how to perform such tasks on linux. My goal is to ...
1
vote
2answers
19 views

Pass length of argument into bash command substitution

I'm trying to write a quick bash function that populates a README.md with a $1\n followed by underscores the length of $1. The code I found in other stackexchange questions showed that to print a ...
0
votes
0answers
9 views

Start interactive bash session with custom config without saving it as a file

I have a string variable that I want to use as a bash rc file (contains aliases and shopt commands), and start a new bash session as a different user. Something like this: sudo su - myuser --session-...
0
votes
1answer
48 views

Changing the color of colored outputs

My terminal has a white background. When commands print yellow text to the terminal, I can't see the text clearly (due to low contrast). I thought: wouldn't it be great if all the yellow text that ...
0
votes
0answers
20 views

Can I write a script to keypress ctrl z or ctrl c for me? What is /e[3J?

Hello I want a bash script that will stop other running scripts. I may prevent the scripts by renaming sudo and test for example but I was also wondering if a CTRL +Z loop would effect other terminal ...
-1
votes
0answers
18 views

Is it possible to make script A both runnable as a script and importable as definitions of functions? [duplicate]

Is it possible to make script A both runnable as a script by another script B and source-able as definitions of functions by another script B? A Python script can be made so by using https://...
2
votes
1answer
41 views

How do you reuse a script in another?

Is it correct that there are two ways to reuse a script A in another script B: script B invokes script A as a command (B creates a child process to run A) organize the code in script A is organized ...
0
votes
0answers
16 views

PHP Bash User input [migrated]

I have a bash script that works as. A user inputs a filename and then the script searches through the directories and when its found it copies to another location so that the file gets re-processed ...
-1
votes
1answer
15 views

bash - use exec for file descriptors using environment variables

LOCK_FD=200 LOCK_FILE=/tmp/lock-file exec ${LOCK_FD}>${LOCK_FILE} I get an error exec: 200 not found This however works LOCK_FD=200 LOCK_FILE=/tmp/lock-file eval "exec ${LOCK_FD}>${LOCK_FILE}...
3
votes
6answers
78 views

How do I match only dotfiles in bash? [duplicate]

rm -rf .* will only not end horribly because rm refuses to delete . and ... How do I exclude these special directories from a glob pattern? This is not solved by dotglob since I want to match only ...
0
votes
1answer
14 views

Use command output as argument in watch command

I have a watch on jq -r '.' $(ls -t | head -1)" The goal is to apply "jq -r '.'" to the most recently modified file in directory. Unfortunately, the command used to know the last modified file is ...
0
votes
0answers
10 views

Unable to source file with aliases in zsh on MacOS [duplicate]

I have created a file with some aliases that I need to from time to time. These aliases are simple kubectl port forwarding commands. For the test purpose, I have left only one alias in the file: ...
2
votes
0answers
43 views

Difference between closing terminal and closing shell on child processes

Opening a new terminal and typing the command firefox& inside, ps -l gives : 4 R 1000 23132 23104 99 80 0 - 2177945 - pts/27 00:00:07 firefox If the shell is closed with the command ...
0
votes
2answers
58 views

Is there something similar or like “pass” in python in bash/shell programming?

I sometimes need a command like pass in Python in my bash scripts. Like: if grep something then pass else code fi In Python you have: >>> for element in a: ... if not element: ...
1
vote
1answer
39 views

The $@ variable is not working in a for loop, trying to iterate through a users list

PROBLEM: I can't get the $@ variable to do what I want in a for loop, the loop only sends one name into the file while looping, it should loop through all the arguments and write them to the file ...
1
vote
1answer
27 views

Processes PPID changed to 1 after closing parent shell

Opening a new terminal and typing the command firefox& inside, ps -l gives : 4 R 1000 23132 23104 99 80 0 - 2177945 - pts/27 00:00:07 firefox If the shell is closed with the command ...
1
vote
2answers
87 views

How do I use shell commands with a directory that contains '-' like '-78059735'? [duplicate]

I have an external program that generates directories with strings that are negative integers. I am trying to use basic shell commands including cd and ls with this directory, for example: cd -...
0
votes
0answers
13 views

Bash script to watch a log file and react to help catch form spam [on hold]

I found your post on SO Best way to follow a log and execute a command when some text appears in the log You are at the very bottom of the post where you made it readable and that makes sense (to ...
-1
votes
0answers
29 views

Using grep to locate and store a line

I am attempting to use a grep command to search a file for a particular substring and if it finds that substring, I want it to store the line that contains it in the variable presented. Assuming my ...
0
votes
2answers
25 views

Can't figure out “Syntax error near unexpected token `done'” issue

I am having the error "Syntax error near unexpected token `done' " and just can not figure out the script. My code is below: trap "rm ~/tmp/* 2> /dev/null; exit" 0 1 2 3 phonefile=~/sournce/...
0
votes
1answer
29 views

How to pass multiple parameters to su <USER> -c “command”

I want to execute composer as non root user. So I renamed main composer executable file to composer-call and then create another executable file called composer. #composer.sh su nginx -c "composer-...
1
vote
1answer
26 views

How to log myself out of ssh, from a bash script?

Connected to a remote server via SSH. On occasion, I run a specific bash script. When certain conditions are met (it's work completed successfully), I wish to be automatically logged out of the SSH ...
2
votes
1answer
42 views

One of the files my application creates “is not a file”

I've been struggling for several days because I run an application that actually runs more application and these generate outputs. The case is that one of these outputs is generated with the following ...
2
votes
1answer
31 views

using both trap and exec to redirect output to tee in bash

I have script that reads lines from a file, processes each line. I'd like to be able to do some "post-processing" in a way that even when the script didn't finish reading all lines because I pressed ...
-2
votes
1answer
39 views

How to store a variable and its value in a file? [on hold]

So I'm basically writing this script where you can create an "account", which should act as a kind of a debit card. I'm generating a random number and storing it in a file for the "account number", ...
6
votes
2answers
44 views

Is it normal that bash stat() and access() much, before commands?

Running strace on the bash shell that is instructed to run mkdir provided this output which shows lots of stats prior to execve the actual mkdir binary: BASH$> strace -f sh -c "bash -c \"mkdir /...
0
votes
0answers
38 views

Ubuntu 14.04.2 LTS: 'find' not found in PATH or not executable

I am trying to install some graphics libraries with the following command: sudo apt install jpegoptim optipng It however fails to run with stating the following: Reading package lists... Done ...
2
votes
4answers
954 views

How to concatanate the result of two Linux commands

Is there an easy way to concatenate the result of two Linux commands, in one line (i.e., without using variables)? I pull the local outdoor temperature from a nearby weather station. The result ...
0
votes
2answers
18 views

Concatenate and use multi line variable in multi line curl execution

With this code #!/bin/bash set -x PROPERTIES="MAINTAINER=Self, My" while IFS='=' read -r key value do ADDITIONAL_PARAMETERS+="-F variables[${key}]=${value} " done <<< "${PROPERTIES}" #...
3
votes
2answers
313 views

BASH: calculate number of days to account expiration

Objective: Output from Linux username, passwordlastchanged, passwordexpires in human readable format. I pulled user info from /etc/passwd and /etc/shadow for users with shell /bin/bash join -1 1 -2 ...
1
vote
1answer
37 views

xargs usage syntax

I am trying to search for a particular string within zipped files but cannot get the 'xargs' syntax correct. The files unzip/zip correctly but xargs is actually searching for nothing (we are looking ...
2
votes
0answers
16 views

lftp mirror error

I have a problem with a script that I am trying to write. Ideally, the script should compress the folders and then send the zipped files to the ftp server creating the folder as the name of the ...
0
votes
0answers
31 views

while increasing ulimit forming error:- “bash: ulimit: open files: cannot modify limit: Operation not permitted”

I'm increasing the ulimit in ubuntu using command ulimit -n 10000 but it gives me error of bash: ulimit: open files: cannot modify limit: Operation not permitted I search for this error. This question ...
1
vote
2answers
50 views

checking if iptables are set on a system in script [duplicate]

I'm writing a script in bash and I need to check if iptables are set...I have this: if [ `iptables-save | grep '^\-' | wc -l` > 0 ] then echo "Iptables already set, skipping..........!" else ...
1
vote
1answer
21 views

Putting a foreground process into the background from a background process

The title is basically my question. Is it possible to put a process into the background from another background process with bash? For instance, if we have the following code: function ...
1
vote
3answers
44 views

Create alphabetic index with letters repeating

I am running Debian 9. In Bash I can echo {a..z} for the alphabet, or echo {a..z}{a..z} to print letter combinations. However, I would like to generate an index with: a b c d etc. then aa bb cc dd etc....
0
votes
2answers
31 views

Properly feed paths to executables in bash script

Hello all I have a text file (1.txt) that contains full paths to binaries which I need to execute a command (val_bin) for each path in the file. 1.txt Example: /source/ed/dev/ed/ab/ed_len/comercial/...
0
votes
0answers
38 views

xargs argument in the middle of command [duplicate]

Why is this command not working? echo 'foo bar' | xargs -I % -L 1 echo yeah % yeah It produces the following output: yeah % yeah foo yeah % yeah bar While I expected the following output: yeah ...
1
vote
1answer
29 views

Stringify bash command from array of arguments for use in “bash -c”

I would like to stringify a given command, given as an array. This would be useful to for example put a command inside a bash -c. For example : cmd=( "printf '%s\n'" "foo bar" "baz bang" ) ...
1
vote
1answer
43 views

Why can't I use read -a to break a string into words? [duplicate]

I have a sample input file called in with the following contents: m@m-X555LJ:~/wtfdir$ cat in asdf1 jkl1 asdf2 jkl2 asdf3 jkl3 I now execute: m@m-X555LJ:~/wtfdir$ mapfile < ./in As expected, ...
0
votes
0answers
13 views

How to modify bash completion for command names to match custom list only?

I want to customize bash completion on command names, such that matches are looked for in a particular list only. If I try the following: complete -E -W "foo bar" it works fine on an empty line, ...