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

1
vote
1answer
23 views

Why is “bind ~/.inputrc” causing my up-right slash key ('/') to be disabled until I re-login?

Below is my .inputrc file. Why, after calling bind ~/.inputrc, is my up-right slash key disabled, until I logout and login again? # Key-bindings for the command-line editor. # Ask before displaying ...
3
votes
2answers
63 views

How to use tee to capture STDOUT from a code block to a filename defined within the block?

I want to send STDOUT for a script block to a file which name is defined by a variable within the block. However, when I use tee, it seems the variable outside the block doesn't exist anymore. Without ...
1
vote
2answers
76 views

Oneliner which prints groups and their numbers which start with a '1'?

I have to write an oneliner which print system groups and their identifiers, for all groups whose identifiers start with '1'. For example, the result of cat command on /etc/group is this: I must ...
14
votes
1answer
350 views

Why is bash not storing commands that start with spaces?

If I perform a sequence of commands like: $ ls $ grep abc file.txt and then use the up arrow key to get the previous one, the terminal will show the last cmd (which is the grep here) But if I do ...
5
votes
3answers
215 views

Save exit code for later

So I have a little script for running some tests. javac *.java && java -ea Test rm -f *.class Now the problem with this is that when I run the script ./test, it will return a success exit ...
3
votes
4answers
457 views

Aggregate and group text file in perl or bash

I have a big text file(with 5m lines) in this format(4 columns, separated by ;): string1; string2; string3; userId The first 3 strings (SHA1s) form a single ID, called appId (so it can be ...
-2
votes
1answer
18 views

'Is a directory' while trying to pass to destination directory

I've been trying to get my script to work from a cron job so that I can automate a backup of my /home directory, but unfortunately when I run with run-parts to test if the script will work I keep ...
2
votes
2answers
1k views

Is there a GUI debugger for shell scripts

Debugging bash scripts on command line is complicated. Is there a good GUI based debugger available for debugging bash scripts?
1
vote
2answers
41 views

Locked out of my own mac terminal?

So recently, some of my friends had been tampering with my files and data through terminal, so I decided to secure it by doing two things: First, I added the following to my ~/.bash_profile for ALL ...
0
votes
6answers
39 views

How do I deal with directories that have spaces in their names from `find`? [duplicate]

I have this: #!/bin/bash for file in `find . -type d` do echo $file done If I have just one directory called My Directory, the output is My Directory How do I fix this? The echo $file is ...
2
votes
4answers
92 views

Flattening folder structure

I have this folder structure: ├── foo1 │   ├── bar1.txt │   └── bar2.txt ├── foo2 │   ├── bar3.txt │   └── bar4 with a space.txt └── foo3 └── qux1 ├── bar5.txt └── bar6.txt that ...
0
votes
1answer
63 views

How do I put a checksum in a script?

I was (am) having trouble installing Eagle on my Linux (debian 8 jessie) computer. I was reading the installer script, when i noticed there is a checksum for the install script in the install script? ...
0
votes
2answers
49 views

Whats wrong with this case statement?

UPDATED: I am trying to do some color changes with my keyboard using apexctl depending on what time it is. But my case statement is giving me trouble. I want to compare the time when the script runs, ...
2
votes
3answers
117 views

How to pass the content of a file as multiple arguments in bash

I have a file that contains data that gets updated over time (mydata). The file looks like this: 1 2 3 With this file, I want to do this (basically handle each number as a separate parameter): ...
3
votes
1answer
57 views

bash runs out of memory

This question is a fork of this SO question. Here is the MCVE version: $ PS1='Parent-$ ' Parent-$ type seq seq is /usr/bin/seq Parent-$ bash $ PS1='Child-$ ' Child-$ for i in $(seq 1000000000); do ...
0
votes
0answers
30 views

how to remove the last two characters of string [duplicate]

I would like to know the more clearly way for remove the last two characters of a string, without calling external commands, I used something like this. A="GOOD MORNING" echo ${A:0:$((${#A}-2))} GOOD ...
20
votes
2answers
15k views

How to remove a single line from history?

I'm working in Mac OSX, so I guess I'm using bash...? Sometimes I enter something that I don't want to be remembered in the history. How do I remove it?
3
votes
1answer
521 views

KSH styling text based menu using STDERR

Is it possible to format the STDERR in order to have a better looking menu using the select command? I have a simple select select oChoice in $(<tempMenu.menu) ; do case "$oChoice" in ...
2
votes
2answers
61 views

Separate filename and path inside find command's -exec option

I'm struggling with escaping and expression evaluation. I am trying to run a command inside a find...-exec COMMAND structure, where COMMAND operates on one file and outputs to the stdout. To use ...
1
vote
2answers
74 views

Get files from SFTP server and manipulate in memory

Is there a BASH way that is able to access a SFTP server, "access" a file and without downloading it read it in a buffer, manipulate the content and then store it locally. I know this can be done ...
0
votes
0answers
20 views

Dynamically Source Bash & Profile Files Across Multiple Enviornments

I'd like to come up with a way to always source the user's profile and bash configuration files upon a interactive login or non-interactive login despite what file structure they may have. It would ...
12
votes
3answers
10k views

Confusing use of && and || operators

I was skimming through an /etc/rc.d/init.d/sendmail file (I know this is hardly ever used, but I'm studying for an exam), and I've become a bit confused about the && and the || operators. ...
53
votes
2answers
9k views

Why does bash think: 016 + 1 = 15?

Can somebody explain to me why a number with a leading 0 gives this funny behaviour? #!/bin/bash NUM=016 SUM=$((NUM + 1)) echo "$NUM + 1 = $SUM" Will print: 016 + 1 = 15
19
votes
5answers
7k views

Why do we need “at” command in linux

I was studying a code in which the at command is used. I looked around it and found that it is used to execute batch jobs. It is used to schedule jobs. Its given a input of command and time ...
7
votes
5answers
2k views

Store 2^500 in a variable in bash

I want to store the value of 2^500 in the variable DELTA. I'm doing export DELTA=$(echo "scale=2; 2^500" | bc) but this does not set DELTA to ...
2
votes
3answers
80 views

Variable expansion in Bash

I tried the following commands variable='one|name' echo $variable The output is one|name whereas echo one|name gives an error No command 'name' found. This is reasonable because bash treats | as ...
6
votes
2answers
908 views

What does `date 2&>$0` do?

I am looking at a co-workers shell code and I saw this: date 2&>$0 I know what date does, but what's 2&>$0 doing? He's out for a while, so I can't ask him what this part was about.
0
votes
1answer
20 views

Adding timestamp into log file via cronjob command [duplicate]

I try to run git pull command with loging output message to file every 5 minutes. But i got error like this, (root) CMD (cd /var/www/sites/ && git pull origin master | sed -e "s/^/$(date ...
3
votes
1answer
168 views

bash [[ = ]] behaviour

man bash: [[ expression ]] [...] Expressions are composed of the primaries described below under CONDITIONAL EXPRESSIONS. Word splitting and pathname expansion are not performed on the words ...
0
votes
1answer
43 views

I am accessing remote machine in linux using Bash scripting

I am accessing a remote machine using the ssh command and a pem file. My code is as follows: #!/bin/bash ssh -i rijo.pem ubuntu@90.45.74.51 <<EOF sudo -s var=`cat ...
27
votes
7answers
2k views

How to determine where an environment variable came from

I have a linux instance that I set up some time ago. When I fire it up and log in as root there are some environment variables that I set up but I can't remember or find where they came from. I've ...
3
votes
3answers
3k views

How can I print only certain commands from a bash script as they are run?

I have a bash script with various if statements based on command line arguments I pass in when calling it. Having some kind of output as to what commands are being run is helpful to confirm the flow ...
2
votes
2answers
50 views

parse one field from an JSON array into bash array

I have a JSON output that contains a list of objects stored in a variable. (I may not be phrasing that right) [ { "item1": "value1", "item2": "value2", "sub items": [ { ...
1
vote
2answers
41 views

Modifying part of a string in bash script

I have a file named variables.f90 , having many lines defining different variables, as follows :: integer::n_monomer=6800 real*8::rx=5.0d0 #... randomly integer and real numbers defined ...
1
vote
4answers
101 views

Bash rename 360 000 files using find -exec

I've got around 360 000 files like: ./001/1/1.jpg ./001/1/2.jpg ./001/2/1.jpg ./002/1/1.jpg ./003/1/1.jpg ... pattern: [60 dirs]/[1000 subdirs]/[4-10 files].jpg I want to rename files using rename ...
10
votes
1answer
435 views

Bash tab completion expands “~” into “/home/___” when it didn't before

Previously, if I typed ~/biTab, before, it would turn into ~/bin. However, today it started turning ~/biTab into /home/username/bin. I would rather have it the former, but I'm not sure what happened ...
22
votes
7answers
29k views

Execute a command once per line of piped input?

I want to run a java command once for every match of ls | grep pattern -. In this case, I think I could do find pattern -exec java MyProg '{}' \; but I'm curious about the general case - is there an ...
4
votes
2answers
488 views

What happens in Bash after calling exit?

I understand that when I call exit, it is an alias for logout. Sometimes, just for fun, when I need to remove myself from a session I will type exit && 1. Now what happens after the exit has ...
15
votes
1answer
2k views

When is double-quoting necessary?

The old advice used to be to double-quote any expression involving a $VARIABLE, at least if one wanted it to be interpreted by the shell as one single item, otherwise, any spaces in the content of ...
0
votes
1answer
71 views

create a user via script

I want to create a new user in a specific group when I issue the below command. sudo ./create_user.sh "test" "firstname lastname" The create_user.sh script looks as below. #!bin/bash #sudo ...
1
vote
1answer
64 views

awk in ssh in su in a command substitution

I am creating a script that will ssh to a host and print all the user accounts and when they will expire. On a host I can run awk -F':' '{ print $1}' /etc/passwd and it will give me a list of all ...
1
vote
1answer
29 views

Killing bash causes it to respawn itself

I'm SSHed into my computer at home and I'm trying to format a drive. lsof /dev/sdb2 shows: COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME bash 1366 mitch cwd DIR 8,18 24576 ...
1
vote
3answers
93 views

How do I test if an item is in a bash array?

Help for a simple script #!/bin/bash array1=( prova1 prova2 slack64 ) a="slack64" b="ab" if [ $a = $b ] then echo "$a = $b : a is equal to b" else echo "$a = $b: a is not equal to b" ...
0
votes
0answers
24 views

Broken mkdir command [duplicate]

I made an alias in my .bash_profile file with the same name as mkdir. It looked like this. alias mkdir='function _blah(){ mkdir "$1"; cd "$1" };_blah' After removing it, i notice that mkdir still ...
0
votes
1answer
43 views

Can't concat file paths, permission denied

I can't realize why if I just try to concat some file paths (without opening the files), I get "permission denied": #!/bin/bash if [ "$#" -eq 1 ]; then path1= "./src/$1" path2= ...
1
vote
2answers
939 views

Changing user to root when connected to a linux server and copying files

My script is coded in a way that doesn't allow you to connect to a server directly by root. This code basically copies files a server to my computer and it works but I don't have access to many files ...
-1
votes
0answers
24 views

How to run a script when install a rpm package and answer the installation questions

I will like to know how to install the RPM and answer the installation question automatically if is possible. any ideas.
1
vote
3answers
117 views

iterate over file and send lines as positional parameters to another file

I would like to iterate through a file containing dates (named dates.txt) in the following format: 2009 08 03 08 09 2009 08 03 09 10 2009 08 03 10 11 2009 08 03 11 12 2009 08 03 12 13 2009 08 03 13 ...
1
vote
0answers
25 views

optimisation of bash globs

Looking for a guide to optimising regexp matches in bash. I have a script that loops over a very long list of URLs looking for patterns. Currently it looks a little like the fragment below. Is there ...
0
votes
1answer
38 views

Is there a way to copy a rectangular area in a bash or konsole terminal?

Is there a way to copy a rectangular area in a bash or konsole terminal? Is something like this supported on the normal terminal, or will it be only available on terminals run in a GUI environment?