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.

learn more… | top users | synonyms

3
votes
0answers
45 views

Memoizing/caching command line output

I have a bash script I use to run a few python and C++ programs in a sequence. Each program takes in some input parameters which I define in the bash script. So as an example I run the program like ...
0
votes
1answer
25 views

how to get the size of an indirect array in bash?

Without using eval. this wont work: astr=(a b c) str="#astr[@]" echo "${!str}"
0
votes
2answers
28 views

operate on different sections of stdin without intermediate file

Is there a simple way to do this with redirection or pipes without creating FILE1? I want to apply process2 to the body of the output of process1, without touching the first and last few lines. ...
9
votes
2answers
160 views

Shell Syntax: How to correctly use \ to break lines? [duplicate]

I used to believe that the appropriate way of breaking the lines in a list is command1 && \ command2 It turned out that it isn't so , one doesn't need \ $ [ $(id -u) -eq 1000 ] ...
0
votes
1answer
40 views

How can I make sure that I'm running an updated version of bash?

I'm learning bash using a Mac, and I just attempted to update bash using: brew install bash sudo -s echo /usr/local/bin/bash >> /etc/shells chsh -s /usr/local/bin/bash Now, ...
3
votes
1answer
32 views

How to always print the prompt on a new line & keep input

We all know this annoying issue: $ printf "abc" > some-file $ cat some-file abc$ which tends to mess up the prompt if it is any more complex than $, throws off the current cursor position and ...
1
vote
2answers
53 views

Check in pure bash that the download is complete

short story is, I probably need a simple loop in bash which checks periodically whether the size of a given file has changed or not since last checked. Long story, I will be downloading a file ...
1
vote
1answer
32 views

How to monitor system performance over time

I wrote the below script to determine how my system is holding up against various games. It checks all the vitals (GPU, RAM, and CPU) and then appends the data to a log file. Is this a reasonable ...
2
votes
2answers
71 views

Combine Two SSH Commands

The first ssh command is done on my computer, I enter the key password, then put the second ssh command in while logged into the server. ssh -i cloudkey -L 6000:localhost:6001 admin@54.152.188.55 -p ...
1
vote
2answers
51 views

How to rename certain directories if the parent has a particular name?

I have to do some global renaming in an Eclipse plugin project, although the fact that the code is Java and it's an Eclipse plugin is irrelevant. Basically, the steps I need to perform are the ...
3
votes
2answers
67 views

regenerate .bashrc from current shell

So I stupidly inadvertently destroyed ~/.bashrc. If I have open terminals with the settings that were previously there, is there a way to export the current settings back to a new .bashrc? (I've tried ...
1
vote
2answers
25 views

How do I remove all files from wtihin a certain directory except for a child directory of that directory?

I’m using bash shell. I have this command to delete all JAR files within a particular directory find ~/.jenkins/jobs/subco/ -name '*.jar' -print0 | xargs -0 -r rm However, I want to modify the ...
0
votes
1answer
24 views

custom shutdown script in rc6.d does not seem to be working.

I'm working with a software application that's a bit touchy so I wan't to shut the software down automatically on reboot or shutdown. I have created a script an placed it in /etc/init.d/ with a ...
2
votes
1answer
61 views

How do I run multiple commands together in the background?

I know I can run a program in the background using &. command & However, I want to run multiple commands, and cd into a different directory while they are running. The multiple commands ...
8
votes
5answers
455 views

Is there a tool to dynamically redirect output to a new file on request

I'm currently redirecting the output of a monitoring tool to a file, however what I'd like to do, is to redirect this output to a new file on my request (using a keybinding), without stopping the said ...
0
votes
1answer
44 views

Bash script fail to detect disk

I got a script that is supposed to reformat and mount /dev/disk/by-label/backup_disk into /mnt/backup_disk. Like this: /sbin/mkfs.ext4 -q -L backup_disk /dev/disk/by-label/backup_disk mount -t ext4 ...
1
vote
1answer
25 views

Bash capturing asterisk inside a file [duplicate]

I have a text file which contains an asterisk as the first character in every line, when I try to process the file in a script like this: while read line; do out=$(echo $line | awk '{ print $3 }') ...
-4
votes
2answers
28 views

How to process only certain columns and ignore header and footer in delimited text file using awk?

I have an input text file called text.txt: Header Column1|Column2|Column3 C11|C12|C13 C21|C22|C23 C31|C32|C33 Footer My output should be: Column1|Column3 C11|C13 C21|C23 C31|C33 My command that ...
0
votes
2answers
39 views

When does an array variable represent the entire array, and when the element indexed by `0`?

Bash manual says: Referencing an array variable without a subscript is equivalent to referencing with a subscript of 0. In Bash or POSIX shell, is there some general rule for when an array ...
1
vote
1answer
30 views

how to inject keystrokes in a program like Safari from a bash script?

I am trying to automate some keypresses every few minutes. The exact timing is still undetermined. But basically I want to capture a live chat dialogue. I'm sure I could do this more elegantly. I ...
0
votes
1answer
61 views

What is the definition of an array being set?

The definition for an array being set is from bash manual: An array variable is considered set if a subscript has been assigned a value. The null string is a valid value. Does it mean that an ...
0
votes
1answer
47 views

command substitution - cat file inserts quotes

In bash, given these files: $ cat noquotes.txt s/a/b/g $ cat quotes.txt "s/a/b/g" Why does $ echo "aaa" | sed -e $(cat noquotes.txt) bbb succeed, but $ echo "aaa" | sed -e $(cat quotes.txt) ...
0
votes
0answers
36 views

In an array, does having an index/key implies that the element indexed by the index/key is set?

In an indexed/associative array, does having an index/key implies that the element indexed by the index/key is set? ( Note that by "set" above, I mean that a parameter/variable is set.) If not, ...
3
votes
3answers
44 views

Conditional PS1

I'm basically trying to make my PS1 look like this when in a git repo: $ ~/Projects/Blah (master): Or if I'm not in a Git repo, I want it to look like this: $ ~/Projects/Blah: This is my current ...
0
votes
2answers
38 views

find composer global install path as root

I have some php packages installed globally using php composer within a script sudo -u me composer global require "phpmd/phpmd" I want to find the path of these globally installed php packages. ...
2
votes
2answers
43 views

Is a subscript to an indexed array an arithmetic expansion?

Quoting from the Bash manual: An indexed array is created automatically if any variable is assigned to using the syntax name[subscript]=value The subscript is treated as an arithmetic ...
1
vote
1answer
41 views

Printing the file with number of hardlinks

I can print the number of hardlinks to files in directory by using find . type f -printf "%f %n\n" but this will also print the hardlink not only original files: Example: file1 is an original ...
1
vote
1answer
39 views

Rc.local not running commands properly

I am running arch Linux and have used this rc-local service: [Unit] Description=/etc/rc.local compatibility [Service] Type=oneshot ExecStart=/etc/rc.local RemainAfterExit=yes [Install] ...
0
votes
2answers
43 views

How to get a correct error code from curl when transfer was closed before getting the whole file

I have a bash-script which calls curl using a proxy. Today there is a problem with the download location. Calling curl ends up with: curl: (18) transfer closed with 7512708716 bytes remaining to ...
1
vote
0answers
25 views

Access to bash arrays in gnuplot [duplicate]

In a bash script I have several arrays which I need to access in a gnuplot code: #!/bin/bash ... # fill array a[*] and b[*] ... gnuplot <<EOF do for [j=0:10] { # access ${a[j]} and ${b[j]} } ...
0
votes
0answers
29 views

Fixing Signal 13 Error on find

I have a situation where I'm trying to install softwares into my system. I'm using a fakeroot approach to install them in a separate directory where I'm listing all the files, directories and links ...
2
votes
1answer
48 views

Tab to show directory contents

I use the terminal app on OSX. Whenever I cd into a deep directory I find it useful to display the successive directory contents as I go. By tapping tab when typing the filepath, it lets me see the ...
0
votes
2answers
65 views

Using regular expression to extract content of file [closed]

I have a link and I would like to return only content between www. and .com e.g www.blablabla.com would return only blablabla How could I do that? When I use grep '\.[a-zA-Z0-9\.-]*\.' it gives me ...
3
votes
3answers
88 views

Display files to size with lower and upper bound without using `find`

I need to create a program via vim in Linux called between. The script takes two arguments as the lower bound and upper bound of the file size, and prints out a list of file names as well as their ...
0
votes
2answers
40 views

How to use file test to check if a file already exists in a directory

I'm trying to write a script that asks the user if they are sure they want to move a file to a certain directory. The script needs to check if the file already exists in the target directory and if it ...
0
votes
1answer
33 views

Is this a correct way to test if a parameter is declared?

Here is an example from http://unix.stackexchange.com/a/56846/674 A different, bash-specific way of testing whether a variable of any type has been declared is to check whether it's listed in ...
3
votes
3answers
83 views

How to prevent script from deleting itself

Hi I'm creating a recycle bin script with the command name 'safe_rm'. I was wondering, how can I prevent the script from deleting its own file. I believe the readlink command is one solution however ...
2
votes
1answer
51 views

Differences between declared, defined, and set

In shell, what are the differences between a variable that is declared, defined and set? Does "declared" mean the identifier of the variable exists, but the storage and value of the variable do ...
0
votes
2answers
44 views

Carriage returns are prevent sed reading all my files

I have a long list of folders, inside every folder I have the file "log.dat". I wanted to read the value of a specific line inside this file. I saved the folders names in a file "All.txt", in the ...
0
votes
1answer
41 views

What is the meaning of $0 in the Bash shell

From Bash Manual $0 Expands to the name of the shell or shell script. This is set at shell initialization. If Bash is invoked with a file of commands (see Section 3.8 [Shell Scripts], ...
0
votes
2answers
98 views

Understand the meaning of `$_`

Could you explain the following sentences from Bash manual about $_, especially the parts in bold, maybe with some examples? At shell startup, set to the absolute pathname used to invoke the ...
1
vote
1answer
23 views

Are the null string and “” the same string?

Bash manual says: A parameter is set if it has been assigned a value. The null string is a valid value. ... If value is not given, the variable is assigned the null string. Is the ...
2
votes
1answer
33 views

No permissions?

Output of ls -l: drwxrwxrwx 16 btsync btsync 4096 Feb 25 15:41 documents I can cd into the folder no problems. Now: sudo chmod 776 documents I can no longer cd into the folder: bash: cd: ...
3
votes
3answers
45 views

set variable inside heredoc and use them outside

I'm trying to set the variable 'count' while running the command inside a heredoc together with timeout, but I'm unable to get the 'count' variable outside the heredoc. How can I achieve that? My ...
1
vote
1answer
78 views

Pattern matching [duplicate]

I am trying to follow Bash Cookbook to learn about Bash Scripting. I am on example 6.8 Testing with Regular Expression. I have the following script: #!/usr/bin/env bash # cookbook filename: ...
1
vote
1answer
23 views

mv command with path wildcard containing random string

Im trying to move a file to a path which has a random string that I cannot know in advance ~/.config/foldername/45fhiu84.dev-edition/subfolder/ I have tried mv ~/Downloads/myfile.txt ...
13
votes
2answers
445 views

What is “<Esc>Kv” in bash

When I am in bash and press Esc, Shift+K, V, bash fires up $EDITOR with a filename similar to /tmp/bash-fc-186566385. Why is that and what is its purpose? I probably need to mention that I am ...
1
vote
2answers
164 views

Bash commands not found

I use CentOS 7 and I install anaconda and some tools, after that some basic command like clear which not work. [zhilevan@localhost ~]$ clear bash: clear: command not found... when I echo $PATH I ...
3
votes
1answer
33 views

Manage Gnome GUI via Bash?

I want to power on the computer and have a Bash script to open all my programs in different Gnome work spaces. For example: Open text editor and CLI in the first work space. Open web browser A in ...
0
votes
2answers
41 views

Can we install a package through a shell script? [duplicate]

I'm trying to write a shell script so that when I reinstall my Ubuntu again. I could just run script and retain all the packages. And I'm planning to pass password in form of argument. My question ...