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

awk + gsub + how to work with all kind of characters

The following awk command target is remove spaces and unnecessary quotes from CSV file and only from single words between separators awk 'gsub(/("[ ]+|[ ...
0
votes
2answers
18 views

How to change to last modified directory in current directory

I'm quite to *nix env and hence excuse me if this is really stupid question. I've an application which generates couple of files in different directories at regular interval and I need to check the ...
0
votes
0answers
10 views

Writing a Bash script to run and end at specific times

I'd like to create a script that will do the following. Start at a given time during the day and end at another given time. So for example, I have a program I'd like to test, so my script would be ...
2
votes
2answers
33 views

split a file, pass each piece as a param to a script, run each script in parallel

I have a words.txt with 10000 words (one to a line). I have 5,000 documents. I want to see which documents contain which of those words (with a regex pattern around the word). I have a script.sh that ...
1
vote
0answers
10 views

When using expect: SSHFS Transport endpoint is not connected

When I run my SSHFS connection script from bash, everything works perfectly. However, when I run the same script using the expect utility, I get the following error when I try to access the folder ...
1
vote
1answer
13 views

X11 Issues running with Terminal.app

I am trying to figure out why I can't use ghostscript or ghostview (or any other X11 applications) when I try to call them in the Terminal. I am using bash, and I also used Fink to get the packages I ...
2
votes
3answers
44 views

moving a (file | directory) while avoiding filename collisions

I have a bash script that moves files from a number of different locations to a folder named completed. I want to avoid overwriting previous files, so in the case when the name of a file (for ...
0
votes
1answer
12 views

For a given directory, how do I concatenate the tail end of recently modified files to a new file?

In case there's a better solution to the problem, my goal is to be able to quickly analyze ALL recent apache activity in /usr/local/apache/domlogs. The usefulness of this is when the server load is ...
1
vote
3answers
34 views

Command to 're-apply' previous command?

Is there an easy way to re-apply a previous command to a new command line entry? Say I typed in chmod u+r,g+x file.txt but forgot the sudo. Could I simply type sudo <some easy symbol>'? ...
-1
votes
0answers
33 views

How to I create a file with a sorted list from users that have mail

I need to create a file ~/you have mail, it needs to contain a sorted list of all users on my local system which currently have mail in their "Inboxes" (i.n., their spool of delivered but no yet read ...
6
votes
4answers
285 views

How can I test if a variable is empty or contains only spaces?

The following bash syntax verifies if param isn't empty: [[ ! -z $param ]] For example: param="" [[ ! -z $param ]] && echo "I am not zero" No output and its fine. But when param ...
2
votes
1answer
21 views

Is using shorthand quick substitution of history expansion problematic?

In my terminal (bash 3), I sometimes use the quick substitution ^aa^bb^ ^string1^string2^ Quick substitution. Repeat the last command, replacing string1 with string2. Equivalent to ...
1
vote
0answers
15 views

Using X11 Displays through Terminal.app commands : generic mapping tools

I am trying to figure out why I can't use ghostscript or ghostview (or any other X11 applications) when I try to call them in the Terminal. I am using bash, and I also used Fink to get the packages I ...
0
votes
2answers
33 views

How to list similar lines?

The delimiters could be: " "; "_" INPUT: foo#foo_ehh113#The password of user 111 will expire within the next seven d foo#foo_ehh204#The password of user 111 will expire within the next seven d ...
0
votes
0answers
32 views

send email only when find finds something [on hold]

I would like to send an email using mutt, whenever this find command finds something, find . /home/user/todel -ctime +30 -type f -ls | mutt … At present it sends an email every time it is run. How do ...
3
votes
3answers
75 views

why bash increment: `n=0;((n++));` return error? [duplicate]

n=0; ((n++));echo "ret=$?;n=$n;" ((n++));echo "ret=$?;n=$n;" ((n++));echo "ret=$?;n=$n;" from n=1 on, ((n++)) works correctly, only when n=0, ((n++)) return error, and I am using a trap '' ERR that ...
2
votes
1answer
31 views

Ctrl-R style interactive search in custom file

I want to be able to search a custom text file similar to the interactive history search in bash. Once the wanted entry is found, executes the line. Bonus Points: have each record contain two ...
2
votes
3answers
75 views

Count files in a directory by extension

For the purpose of testing, I'd like count how many images files are inside a directory, separating each image file type by file extension (jpg="yes". This because later it will be useful for another ...
2
votes
1answer
42 views

Forward SIGTERM to child in Bash

I have a Bash script, which looks similar to this: #!/bin/bash echo "Doing some initial work...."; /bin/start/main/server --nodaemon Now if the bash shell running the script receives a SIGTERM ...
1
vote
1answer
30 views

processing multiple extensions

I have done a script to convert recursive .jpg files to another size: echo $re mkdir "$re"_tmp for a in *.jpg ; do convert "$a" -resize $re "$re""_tmp/${a%.*} ["$re"].jpg" ; done I'd like integrate ...
1
vote
1answer
56 views

Resolve nested aliases to their source commands

I've made several aliases for my convenience.But now I need to be helpful by sending a useful command and it is full of aliases.I've tried doing type u but all it returns is up && ap upgrade ...
4
votes
1answer
33 views

Is it possible for bash completion to cycle through the alternatives?

When using bash completion and an a number of characters have been entered, tabbing ceases to work then the prefix you have typed is matched by more than one of the possibilities. Is there a way to ...
16
votes
2answers
647 views

Does ~ always equal $HOME

I know this has probably been asked before, but I couldn't find it with Google. Given Linux Kernel No configurations that change $HOME bash Will ~ == $HOME be true?
2
votes
2answers
51 views

Meaning of backslash

Why the following command prints Smith but not \Smith? echo \Smith
4
votes
1answer
100 views

Proper way to distribute shell scripts

What is the most proper way to distribute shell scripts, if behaviours of shells can be modified by set and thus are unpredictable? For example, rm *.txt wouldn't be executed as expected on the ...
3
votes
3answers
49 views

Is it possible to have a bashrc for a usergroup?

Is it possible to execute some bashrc file for all users in a group? If you can do that system-wide in /etc/profile then why not for a usergroup?
-1
votes
0answers
45 views

Unique id for combination of Latitude - Longitude

I have a LibreOffice Calc table containing one column with latitude and one with longitude. What I want to do is for every unique combination of latitude and longitude a unique number to be assigned ...
1
vote
2answers
86 views

Chown permission denied on owned dir

I have following directory (/usr/local) rwxr-xr-x. 43 root root 4096 Jul 25 14:19 . rwxr-xr-x. 14 root root 4096 Feb 21 10:27 .. rwxr-xr-x. 2 root root 4096 Jun 28 2011 bin [...] rwxr-xr-x 1 ...
4
votes
4answers
151 views

Indirection on a Bash array

Is there a possibility to write the following script without the loop? IPv4_first=1.1.1.1 IPv4_second=2.2.2.2 IPv4_third=3.3.3.3 IPv4_all=() for var in ${!IPv4_@} do IPv4_all+=(${!var}) done ...
1
vote
1answer
21 views

dialog --inputbox

Follow the below script I've a unique variable that keeps all variables, I need have each variable separated from $VALUES: #!/bin/bash shell="" groups="" user="" home="" exec 3>&1 ...
2
votes
2answers
65 views

How to write a function in bash?

I am drawing blank here. How should I have written this script? #!/bin/sh XZY_NODES="\ vl-ocnt-1 \ vl-ocnt-2 \ vl-onet-1 \ vl-onet-2 \ vl-ocmp-1 \ vl-oomp-2 \ " is_xyz_node () { host=$1 ...
2
votes
2answers
75 views

How to clear the input in Bash

I have a bash script that is reading quite a bit of data /dev/random. I need the user to type randomly to seed the random daemon. However once the script completes everything typed will get dumped to ...
1
vote
0answers
27 views

Can I change uuid for network interface in ifcfg-eth* using uuidgen?

I'm creating a script which configuration the network interfaces. The script which generates /etc/udev/rules.d/70-persistent-net.rules and names interfaces to my preference. In CentOS 6.5, my ...
5
votes
2answers
67 views

“command | less” vs “less <(command)”

A common "idiom" for viewing large amounts of command output is to pipe it to less, via command | less. However, it's also possible (perhaps only in bash, haven't tested in other shells) to use the ...
1
vote
3answers
55 views

Creating an alias for a bash script

So I have tried experimented and created an alias in .bashrc. However, when I test out the command I get: [rkahil@netmon3 ~]$ menu -bash: menu: command not found Here is what I have in the .bashrc ...
0
votes
0answers
27 views

bash script loses readonly value after first time thru loop

I have a bash script which seems to lose the value of the readonly constant after the first time thru the for-in loop. For example: #!/bin/bash readonly DIR="./groups/" for output in "${array[@]}" do ...
0
votes
1answer
39 views

Test firefox in a loop

I would like to simply bash the following: start firefox, test it, kill its process if it does not work and restart it; or stop the script once for all if it works. Actually I need a awk sentence to ...
1
vote
1answer
43 views

Memory buffer in a bash script

I have recently finished a script that will ask for a hostname and automatically take the argument of the function and ssh into one of my work servers. Here is a copy of my script: #!/bin/bash echo ...
7
votes
4answers
239 views

How can I suppress the space between generated arguments during brace expansion?

I used the following command to create a list of URLs that I want to test: echo -e ...
3
votes
0answers
18 views

Errtrace and local

I am using the following script: #!/bin/bash -Eu trap 'echo Hi' ERR exit_failure() { echo "Hello, World!" return 1 } sub_failure() { res=$(exit_failure) } sub_failure It results in the ...
0
votes
1answer
43 views

how do I recursivley grep (or otherwise search for) hex strings

Long and short I'm trying to track down some files left by evil scum on a server. fgrep -r "STRING" /path/here has been working well for finding general stuff. However, how do I search for hex ...
8
votes
3answers
371 views

Creating a Bash script that will execute a program and if it exits without crashing, will run it again

I'd like to know the easiest way of creating a bash script that will run an app in MacOSX (it's a UNIX based system so I assumed this was the right place). wait for the program to exit. If the exit ...
9
votes
3answers
78 views

Bash autocomplete with vim command

In bash, autocompletion of paths has recently stopped working when issuing vim commands where the path is deeper than two directories (it continues to work as expected with other commands, such as ls ...
6
votes
2answers
418 views

Why is `tac file | grep foo' (piping) faster than `grep foo < <(tac file)' (process substitution)?

This question was motivated by "Reverse grepping", about grepping a huge file from bottom up. @chaos said: tac file | grep whatever Or a bit more effective: grep whatever < <(tac file) ...
3
votes
2answers
29 views

bash 'nounset' on sub-shell/child doesn't force main script to exit, how to workaround that globally?

With this script: tstNounset.sh #!/bin/bash set -x set -o nounset;set -u echo `echo $str` function FUNC1() { echo $str; };export -f FUNC1;bash -c FUNC1 function FUNC2() { set -u;echo $str; };export ...
4
votes
0answers
83 views
+50

Bash inside Vim not working properly

In MacVim I'm using Conque to run bash commands inside Vim. I have a problem with the text navigation while using Conque. If I'm at the end of a line of text and press down Alt← I skip a word to the ...
0
votes
0answers
54 views

Mirrored Linux Commands [closed]

I've encountered two incidents where commands (or logic flow) is given forward and backwards In bash scripts: if ... fi (use to closed an if-statement) and in GNU/Linux command line: cat; tac (cat ...
5
votes
3answers
96 views

Run program with environment set to variables in a file

I would like to run a program (in this case Python) with only the environment variables defined in a file, say vars.env: FOO=bar X=12 Here's a simply Python script that prints the environment: ...
1
vote
0answers
15 views

Mirrored Linux Commands [duplicate]

I've encountered two incidents where commands (or logic flow) is given forward and backwards In bash scripts: if ... fi (use to closed an if-statement) and in GNU/Linux command line: cat; tac (cat ...
3
votes
1answer
43 views

How do I stop a bash shell PS1 color to stop at the end of the command?

So simple question really, I have a custom PS1 colour where I have the actual shell commands in a distinct colour, just so I can quickly see what commands I typed and separate it from the command ...