Questions about bash only, as opposed to other Bourne/POSIX shells. For all Bourne/POSIX-style shells, use the /shell tag instead.

learn more… | top users | synonyms

0
votes
1answer
13 views

Force bash to respect newlines in command output [duplicate]

When I run ls * its returning entries delimited by a newline. However my shell is ignoring the newlines to condense the output. I would like each entry on a separate line. Currently: > ls * a b c ...
0
votes
1answer
24 views

Bash script not working with crontab

I own a raspberry pi that runs raspbian jessie. I'm using this raspberry with motioneye as a system surveillance. Motioneye records files to a sd card but i want to delete older files in folder ...
1
vote
3answers
28 views

How to improve bash scripting from 1 long line to a better method?

I have a script that open up terminal and open up 5 tabs, execute a certain command, and go to a certain working directory. #!/bin/sh gnome-terminal --tab --title="Zookeeper" --profile Hold -e "sh ...
1
vote
1answer
19 views

What does <(command) do? [duplicate]

I was reading this script someone wrotte and there is this line: comm -23 <(grep cat access.log) cats | mailx -s subject address@gmail.com I understand it to mean convert this output as if it was ...
1
vote
0answers
18 views

Scope of variables in a process substitution

I have a command which takes two arguments. Assume we want to create both arguments by process substitution: cat <(var=123; echo $var) <(echo $var) What has to be done, to make $var available ...
1
vote
2answers
15 views

How to reverse sort the output from grep -rc

I want to be able to sort the output from the grep -rc command, I am currently using the command: grep -rc "Pattern" . | sort -t: -rk2,2n however the list is still sorted from low to high, ...
0
votes
1answer
6 views

Using extglob to glob/download over folders titled SRA111 through SRA190

I am trying to download some files on NIH public database via ascp (Aspera Connect). Essentially there are directories SRA111, SRA112, SRA113, SRA114, SRA115,..., SRA190. I need to download all the ...
0
votes
2answers
25 views

Help creating script to move files based on date or filename

I have an FTP process that is constantly putting files into a directory. The date created is part of the filename in a format like this: YYYY-MM-DD-HH-MM-SS-xxxxxxxxxx.wav I would like to move the ...
1
vote
1answer
30 views

How to assign a variable within a pipe

I'm building a one liner in bash. If making a script or writing temp files were an option, I wouldn't need to ask. I need to assign a variable in the middle of a set of pipes to use down the line. ...
3
votes
4answers
39 views

Provide default value if command returns with non-zero exit code

I have some configuration in file config and would like to cat that file. However, sometimes config doesn't exist. In this case, I would like to have my command output a default value. Perhaps ...
1
vote
1answer
31 views

Bash: Iterating 2 lists using single For In loop

Suppose I have 2 seperate loops for file1 in `ls Dir1/` ; do echo $file1 done for file2 in `ls Dir2/` ; do echo $file2 done I want Single loop to iterate both Directories pseudocode for ...
4
votes
2answers
66 views

Bash output redirection to sub directory of current directory

I'm very new to using UNIX/Bash. I'm currently outputting the product of a random number generator to a text file in a subdirectory using the following: ./generate > ...
1
vote
0answers
18 views

Filtering JSON request with JQ and bash scripting

I'm requesting a JSON from Twitch with: curl --silent -H 'Accept: application/vnd.twitchtv.v3+json' -X GET https://api.twitch.tv/kraken/streams/$1 where $1 is the input I send for my function. Now ...
2
votes
1answer
17 views

Is it possible to configure bash to autocomplete with one tab like zsh?

As most people here know, when using bash at the command prompt if you partially type a file name a command or an option to a command etc, bash will complete the word if there is exactly one match. ...
0
votes
2answers
28 views

How to read a file into a shell script as a variable?

I need to write a shell script to read a text file in and perform operations on it to count all distinct words in the text file. I have all of the commands needed to do these operations, but how ...
0
votes
1answer
19 views

BASH script that check disk space and send email [on hold]

I wrote the script that checks disk space usage on specific partition. Cron executes script every 5 minutes. What I want to do is to implement check which will check if mail is sent in last hour and ...
2
votes
2answers
58 views

Is a sub-shell the same thing as a child-shell

There are this two names: a subshell and a child-shell. Yes, a child process will be started by any of this: sh -c 'echo "Hello"' ( echo "hello" ) echo "$(echo "hello") echo "hello" | cat Are all ...
3
votes
0answers
22 views

The environment given to a program vs the execution environment in which the program is invoked

Bash manual says When a program is invoked it is given an array of strings called the environment. This is a list of name-value pairs, of the form name=value. What are the relation and ...
0
votes
1answer
20 views

Comparing 2 directories and copying the different sub-directories to a 3rd directory

I have 2 directories DIR1 and DIR2 DIR1 is base directory, where new changes come often, sometimes new sub-directories as well. DIR2 has older version of files. I want to compare these 2 ...
0
votes
1answer
47 views

How can we prevent parameter expansion?

How can we prevent parameter expansion? Does the Bash's Manual mention this somewhere? I'd appreciate if you could help me to locate where it is mentioned there. For example, $ b=1 $ echo $b 1 ...
0
votes
1answer
24 views

Reading file using shell script, format of the line has changed

I am reading a file using the following code: displayLine(){ echo $line } filename="SampleFile" while read line do displayLine $line done < "$filename" The format of the file that I am ...
-2
votes
0answers
30 views

Do a bash script and `bash -c <command>` run in a subshell environment? [duplicate]

In Bash Manual Command substitution, commands grouped with parentheses, and asynchronous commands are invoked in a subshell environment that is a duplicate of the shell environment, except that ...
0
votes
1answer
48 views

cp doesn't work in a script but does from the command line

I have this script for automating a simple process where I scan a number into the command line, grep that number out of a catalog file which gives me a path, and then copy the DVD which the above ...
0
votes
4answers
45 views

Grep for a string and then echo a string back from a record

I have the following record: MiraServ.log.10:2016/02/07 15:25:13 3 All stations busy!! MiraServ.log.10:2016/02/07 15:25:13 1 TranHasError (3627,-2) ...
1
vote
1answer
35 views

Bash: Default variable with command substitution

Is there any way to accomplish the following in one stroke using Bash? my_var=${$(grep -E '^setting_1' /settings.conf):-default_setting1} As opposed to: my_var=$(grep -E '^setting_1' ...
2
votes
1answer
29 views

Inside a bash script doing an ssh, automatically add the host only for certain known RSA keys

I have a Chron job running a bash script that then SSH's to a my server. But my server's IP address changes from time to time (my bash script has a way of finding looking up the new IP address). But ...
0
votes
1answer
21 views

Remove file name when recursively counting number of occurrences of a pattern

When I run my grep command: grep -rc 'PATTERN' . it prints out the number of lines that the pattern occurs, but it looks like this: ./hotel_232424.dat:234 and so on... How would I remove the ...
0
votes
1answer
24 views

Update 'changing' variables every time PS1 is called, i.e. every new prompt [duplicate]

The reason I need to be able to do this, is to have 'updating' variables in my PS1. I'd like to have my prompt span across the entire width of the terminal, not wrapping around or going down to a new ...
0
votes
0answers
17 views

Delete Non numeric row from a csv

I have used sed to allow only numeric and csv format ,I have used sed '/[^0-9, -, .]/d' as regex. It has still "_","1-0","1-1" character as o/p which worries me. sed 's/'"$(printf '\015')"'//g' ...
2
votes
3answers
40 views

How to alias rm to always confirm

When I use the command rm -rf, I want to make sure a prompt always appears before deleting a file, so I tried adding this to ~/.bashrc alias 'rm -rf'='rm -rfi' But it doesn't work. How can I fix ...
0
votes
1answer
26 views

creation of a variable, and assignment of a value to the variable

From Bash manual, a parameter is set if it has been assigned a value. In bash, are the following two different concepts: a variable exists a variable has been assigned a value, i.e. is set? unset ...
2
votes
3answers
141 views

Why are non-environment variables passed to the subshell invoqued by command substitution?

Bash manual says: Command substitution, commands grouped with parentheses, and asynchronous commands are invoked in a subshell environment that is a duplicate of the shell environment, except ...
0
votes
1answer
37 views

Convert a column of epochs into a time column starting from 0

What I have Hi, imagine a lot of this files, where first column is epoch, and the other(s) column(s) are some data: 1000333,34,1 1001456,56,0 1005356,34,2 What I need I need to transform them ...
0
votes
1answer
13 views

Trouble using if string in column 3 of .csv exist, then statement

I have a set of 10 files. 5 are unique tumors tissues and the other 5 are matching normal tissues… So {tumor_A, normal_A, tumor_B, normal_B,… tumor_E, normal_E} These files each have a random ID, ...
0
votes
1answer
13 views

Centralising Discs to Repository?

I have discs where is much variations. I would like to add the files to my central repository. However, I am getting warnings about ownership. I am thinking of running sudo chown -R masi:masi ...
0
votes
3answers
29 views

Backup script fails with the rsync command's options in a quoted variable

Using: rsync version 3.1.0 protocol version 31; Linux Mint 17 (based on: Ubuntu 14.04.3) In one of my backup Bash scripts, which uses rsync, I put the rsync options in a variable like this: # Set ...
1
vote
2answers
24 views

Unexpected field expansion behavior by bash for loop

I am having a problem reconciling all of the field expansions rules in linux/unix, so I've been experimenting. Here is an example which based on my reading is not consistent with what I'd expect. ~$ ...
1
vote
3answers
37 views

How to determine callee function name in a script

To make it short, doing something like: -bash$ function tt { echo $0; } -bash$ tt $0 will return -bash, but how to get the function name called, i.e. tt in this example instead?
1
vote
1answer
36 views

Remove a part of a path from a variable content

In a Bash I have a variable: LOCAL_PATH="/this/is/a/path/" Then I have another variable, which content starts with LOCAL_PATH and it should be removed: LINE="/this/is/a/path/which/is/longer" The ...
1
vote
2answers
94 views

What do you use when you can't use Bash? [on hold]

I am trying to make a shell script that runs on a widest variety of *nix systems. So, if I wrote a bash script backwards compatible with old versions of the shell, but what if bash wasn't on the ...
0
votes
2answers
40 views

Check if a file contains a certain pattern?

#!/usr/bin/expect -f ps ps -ef > test.txt Now if I want to check whether test.txt has certain keywords present, in it, how do we go about? say: 'apache' or 'fast' Can we use the if statement ...
3
votes
1answer
30 views

grep output of cdrecord

I would like to parse the output of cdrecord/wodim using grep. cdrecord -v outputs lines like Track 01: 49 of 75 MB written (fifo 100%) [buf 100%] 10.2x. The problem is that cdrecord uses ...
-4
votes
1answer
44 views

Simple bash script to print prime numbers from 1 to 1000 [on hold]

How can I make a POSIX script that will print all the prime numbers from 1 to 1000? Lots of thanks
3
votes
3answers
359 views

How can I use '*' to capture everything with exceptions

For example, I have files named A_1.txt A_t_1.txt A_ts_1.txt A_tsa_1.txt in a directory ~/admin/packages/. I am building a for loop to by globbing to A_1.txt for f in ~/admin/packages/*_1.txt ...
0
votes
2answers
44 views

Bash - Redirect output to a variable or file descriptor, then read from the variable or file descriptor

Here's an example of a bash script that redirects all output to a file (and shows output on the screen too): # writing to it exec > >(tee --ignore-interrupts ./log) exec 2>&1 echo "here ...
0
votes
0answers
28 views

Include text from other file in screen printf

The original code of main.sh: screen -S myscreenname -p 0 -X stuff "`printf "myabcdefg"`" I want to put only abcdefg (without my) in other file. Below codes works just fine but I need the text.txt ...
3
votes
4answers
51 views

how to access the next argument of command line parameters in bash?

Say I have the following: for i in $@; do echo ${i+1} done and I run this on shell $ test.sh 3 5 8 4, it outputs 1 1 1 1 why wouldn't ${i+1} work? I am trying to access the next argument for a ...
1
vote
2answers
25 views

Should the operands to a utility always appear after all the options to the utility?

POSIX says utility_name[-a][-b][-c option_argument] [-d|-e][-f[option_argument]][operand...] ... The arguments following the last options and option-arguments are named "operands". ...
0
votes
2answers
76 views

How is a command following the while command executed over the loops?

In while <command> part of a while loop, is <command> executed in each loop independently of other loops? In the following example, why can the while loop make read read all the lines of ...
0
votes
2answers
47 views

Command to skip process if file exists

I have been using a for loop to run a pipeline for multiple files but unfortunately the terminal froze halfway. I would like to run the pipeline again but because of time I would like to skip the ...