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
8 views

Variable assignment outside of case statement

In many languages it is possible to assign the result of a case/switch statement to a variable, rather than repeating the variable assignment many times within the case statement. Is it possible to ...
3
votes
1answer
54 views

Explain this bash script

Consider the following bash script: #!/bin/bash echo "${1##*.}" This script prints the extension of a file if the file name is supplied as the first command line argument, something like ...
1
vote
1answer
12 views

Read Multiple Entries from an Input File

I wrote a program in Fortran that asks me for latitude and longitude and the name of the output file every time I run it. It works great. What I have been meaning to do is run this program for the ...
0
votes
1answer
14 views

Point program without garbaging up alias (~/.bashrc)

What is the correct way to point to a program/script without passing the command through aliases in the bashrc? For example: I create a custom script MyScript.sh. I wish to create a command that can ...
4
votes
3answers
135 views

Is it safe to use a bash script to create a daemon?

I would like to create an entirely automated box (based on something like a Raspberry-Pi or OLinuXino card). My box would run a Debian based system with a read-only filesystem and a ramdisk (to avoid ...
0
votes
1answer
33 views

Compare two strings in a shell script [duplicate]

My script needs two arguments. I want to hide the error message if someone calls the script with script.sh --help so I tired this: if [ $# -ne 2 ] ; then if [ "$1" -ne "--help" ]; then echo ...
0
votes
1answer
31 views

How to evaluate a variable length in shell script?

I want to write a shell script, in which it will call different command according to the variable length. But I didn't figure it out yet. My unwork script is here: for i in n5 n25 if ${#i} == 2; ...
1
vote
3answers
133 views

What is $() in a command?

What is $() in Linux Shell Commands? For example: chmod 777 $(pwd)
2
votes
1answer
16 views

Change the PS1 prompt in a subshell sh called from parent bash

When I am running an interactive bash session, I sometimes experiment with sh. I call sh directly from this bash session. My question is, how can I change the PS1 prompt of this subshell? I would ...
1
vote
2answers
89 views

replace lines in a text with matching text

Original file 123|abc|heloo good morning friends|1|123|abc|123|abc 123|abc|heloo good morning everyone|1|123|abc|123|abc Replaced file 123|abc|heloo good morning freinds|1|123|abc|123|abc ...
0
votes
1answer
36 views

Answer password prompt programmatically via shell script

I would like to programmatically answer a password prompt using only shell script when prompted. Is it possible to automate this task in this way? I want to avoid other tools entirely - so no expect ...
0
votes
0answers
15 views

X11 Path Issues and Confusion for Installed Packages

I am using GMT (generic mapping tools) and SAC (Seismic Analysis Code), and each use X11 (or XQuartz on 10.9.4 Mavericks) to display graphics. When I want to display postscript using ghostview, I get ...
0
votes
0answers
19 views

Join 2 files on 2 columns returning 0s

I have 2 files, that are sorted, with 3 columns each. I need to merge them based on the first 2 columsn and return 4 columns, being the 2 that are matching and then the 3rd column from each file. I ...
3
votes
2answers
63 views

Move every file that is not a directory

I have a directory that I am trying to clean out that contains both files and subdirectories. What I am trying to do is simple: move all the files into another directory, but leave all the ...
1
vote
2answers
35 views

Using if statement with or to validate arguments for shell script

I'm working on a bash script to restart multiple apache instances in different environments. It's working fine except I'd like to add some logic to ensure only correct arguments are entered. I've ...
1
vote
1answer
23 views

How can I use global variable arrays in aliases or functions

I am attempting to simplify repetitive work procedures. In doing so, I am trying to write a .bashrc script which will set global path variables that aliases can refer to. Disclaimer: I'm new to linux ...
-4
votes
3answers
53 views

Birthday reminder

write a bash shell script to get the alerts of friend's birthday Suppose Birthday Date Friend's name 08-02-2014 : Prashant 08-15-2014 : prabhat 09 -16 -2014 ...
3
votes
1answer
87 views

Preserve formatting when command output is sent to a variable? [duplicate]

I have a bash script. If I run this command to: grep for certain patterns, transform the output, sort the output dedupe the output then I get one grep find per line in terminal LC_ALL=C grep ...
0
votes
2answers
42 views

how to remove all double quotes from csv except specific field

I want to remove all double quotes from my csv but not the fourth field (because the four fields represent PATH of file) Please advice how to implement this by sed or awk or perl one liner , etc ...
2
votes
1answer
13 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(/("[ ]+|[ ...
2
votes
4answers
93 views

Change to the last modified subdirectory of the current directory

I have an application which generates a couple of files in different directories at a regular interval and I need to check the latest files generated, i.e. the file which is generated in the most ...
0
votes
1answer
38 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
45 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
1answer
15 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
16 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
50 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
14 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
35 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
34 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 ...
8
votes
6answers
362 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
22 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
16 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
34 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
34 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
80 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
44 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
57 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
35 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 ...
18
votes
2answers
693 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
111 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
47 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
90 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
152 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 ...