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

7
votes
2answers
223 views

How to avoid space after bash variable in string?

I have a variable for color. I use it to set color to strings, by evaluating it inside the string. However, I need to include space after the name(so that the name doesn't contain part of the text). ...
-7
votes
0answers
41 views

what does “-rwxr-xr-x 1 root root 920788 Mar 28 2013 bash” mean? [duplicate]

I am doing a school assignment, I am struggling abit because I am not a frequent mint user. Could someone please explain to me in detail what this means. -rwxr-xr-x 1 root root 920788 Mar 28 2013 ...
1
vote
1answer
25 views

Debian : Setting path for Node with root accessible globally

I have downloaded NodeJS setup and have it inside at /home/deploy/nodejs. I am trying to set its path, but it's not working out. I am logged in as root, and I would like to access nodejs and npm ...
5
votes
3answers
250 views

How to subtract 1 from numbers matched by regular expression?

I'm trying to write a script that reduces each number in line by "1", but I'm getting all "0"s instead: awk '{a=gensub(/([0-9]+)/,"\\1","g",$0); if(a~/[0-9]+/) {gsub(/[0-9]+/,a-1,$0);} ...
0
votes
3answers
52 views

Perform parameter expansion before brace expansion? [duplicate]

Bash manual says that brace expansion is performed before any other expansions. I am writing a script which accepts two arguments: #! /bin/bash for b in {$1..$2}; do echo $b; done I run it like: ...
3
votes
1answer
48 views

Why does bash 4.3 keep allocating memory in a script

Why does this shell script gradually consume more memory in bash? I’m not using any local variables and although the value of cpid is changing at every iteration because ls exits immediately, but it ...
4
votes
5answers
424 views

Can I display GIT in prompt when current directory has a .git folder?

Can I display GIT in prompt when current directory has/contains a .git folder? Is there a way to do this? My current prompt is defined like so: export PS1="[\u@\h] \w $ " So, my prompt looks ...
3
votes
1answer
35 views

integer expression expected

I have the following script that is trying to match and IP address with a value in a file #!/usr/bin/env bash #To find the IP via ping ping=$(ping federicolivieri.noip.me -c 1) #To cut the result ...
1
vote
4answers
41 views

Bash file - find value from command output and keep as variable

I am trying to make a script that will conntect to a ups and get the battery value and store it in a variable. I have managed to connect to the ups and get infomation from it but I am strugling to ...
1
vote
2answers
25 views

Is it possible to start tmux visible session

The code below will run source ~/.bashrc under tmux but this will not open tmux on the terminal. #!/bin/bash tmux new-session -d -s my_session 'source ~/.bashrc' I want the below effect from the ...
1
vote
2answers
37 views

Get full directory of $file

My first shell script #!/bin/bash echo "Input your file" read $file path=(readlink -f $file) echo "$USER, $path" >> scriptlog.txt it said missing operand. How can I fix it?
0
votes
1answer
36 views

how to compress all folders in a directory

I have a directory full of folders and I was wondering if there is any command to compress all the folders in a directory X with date in the name of the file and not update old ones in case they ...
1
vote
0answers
37 views

What does the `$>$` mean in the command `badblocks /dev/fd0H1440 1440 $>$`? [closed]

In the book 'Linux System Administrator's Guide' in website Linux System Administrator's Guide, the command badblocks /dev/fd0H1440 1440 $>$ is in section 5.10.4. Creating a filesystem, so what ...
-1
votes
2answers
45 views

shell script replace and add next line with special characters [closed]

I am trying replace a line with another line and add new line below that using a shell script. I want to replace: export PATH with: ...
0
votes
1answer
25 views

Source ~/.bashrc when using the shell recorder `script`

I am using the first answer from How to automatically record all your terminal sessions with script utility to record my terminal sessions, however, I can not figure out how to get my bashrc to be ...
0
votes
1answer
56 views

associative array with two strings

is it possible to loop a simple array with key and value with a string in the [key] part ? #!/bin/bash -x wget url://stringlist1 wget url://stringlist2 #cat/sed some stuff .... declare -A ...
0
votes
1answer
51 views

Parse xml returned from curl within a bash script

I've been digging through stackexchange for the past few days and I've found bits and pieces of what I'm trying to accomplish, but I'm unsure how to put it all together... I'm trying to create a ...
1
vote
2answers
30 views

How to color some strings in a file

I prepare a file Hello.txt as follows. 1253125213 213532135 23513125215 Then, I want to color each line blue except "2", and color the "2" red. At first, I wrote BLUE='\033[0;34m' ...
-5
votes
1answer
49 views

help with a bash shell script that creates directories

I have a problem I been trying to tackle. If anyone can help, it would save me a headache! For reference,I started self learning so I'll be looking for problems around but can't find the answer for ...
1
vote
1answer
25 views

Compare and merge config file in CentOS

I was trying to setup an auto-update (for multiple servers) bash script via cron to a config file (text based) by downloading the new file everyday and replacing it directly. The script works fine, ...
2
votes
2answers
59 views

bash read of a newline, printf reports character 0

I use bash printf function to print ASCII codes of characters in an input file, but for some reason printf outputs ascii code 0 for LF characters, instead of 10. Any ideas why? while IFS= read -r -n1 ...
0
votes
1answer
49 views

Reading user input with read back

when I use simple bash command #!/bin/bash echo Please, enter your name read NAME echo "Hi $NAME!" and run it using source filename.sh it gives me an error :Undefined variable what could be the ...
0
votes
1answer
57 views

Why “lsof” is not working when it used in ssh? [duplicate]

I found this command line is not working ssh i01n10 "/usr/sbin/lsof -p $(pgrep -nf a.out)" it shows the error lsof: no process ID specified However ssh i01n10 "$(pgrep -nf a.out)" ...
3
votes
2answers
71 views

Why does ls .* show different files than ls ./.*?

Blank file .ignoramus in current directory exists. bojan@localhost:~$ echo $GLOBIGNORE .ignoramus bojan@localhost:~$ ls .* | grep ignor bojan@localhost:~$ ls ./.* | grep ignor ./.ignoramus tools ...
0
votes
2answers
23 views

Why does ls still show the file excluded via GLOBIGNORE?

File missing with echo but present with ls -a. Why? bojan@hyperion:~$ touch .ignoramus bojan@localhost:~$ ls -al | grep ignor -rw-rw-r-- 1 bojan bojan 0 Apr 19 19:05 .ignoramus ...
1
vote
2answers
39 views

Using awk to combine two csv files on three fields too create a new csv file

I would like to compare fields in 2 csv file and create new csv file for output. I have 2 csv files; this first file is PCs in my network: ...
2
votes
1answer
65 views

Multi processing / Multi threading in BASH

I have a test file that looks like this 5002 2014-11-24 12:59:37.112 2014-11-24 12:59:37.112 0.000 UDP ...... 23.234.22.106 48104 101 0 0 8.8.8.8 53 68.0 1.0 1 0.0 0 68 0 48 Each line contains a ...
1
vote
0answers
26 views

Forward stdout to different tty

I have an external device, that I can send commands to, and it would respond in a certain way. For this I use two terminals, one sending the commands and one listening to the response. At some point I ...
0
votes
1answer
27 views

How to Wget with Subset Condition?

I want to download a subset of data recursively in the website that is within HTML class .container current main page in .container daughter pages of links also in .containers in daughter pages ...
1
vote
1answer
23 views

Triggering an event based on output of a second command

I'm scripting a deploy to cloud foundry using the CF CLI, and would like to capture the logs related to the new application being started up for analysis. This requires two different commands ...
3
votes
3answers
244 views

Using grep with a pattern that contains a variable to be expanded

I have a file on the form 2e95d7582c53583fa8afb54e0fe7a2597c92cbba 1461065389 52880 temp/hello/file.txt 46c897a7aa8a641f46080b3431860bd0cd4a8f05 1461066221 207 temp/Another file.txt ...
0
votes
2answers
45 views

backspace doesn't work when running c++ program

Whenever I use ./a.out to run a c/c++ program in bash, I cannot backspace when entering input. Instead I got a box with a question mark.
0
votes
1answer
30 views

log script output to file and terminal at the same time

I have a simple tcpnotification receiver script that logs notifications. At first I just printed the notifications in terminal but then changed script so that notifications are logged in a file. But ...
-4
votes
1answer
49 views

Is the value of a variable lost after a command is executed?

There is a functional difference between using: n=$1 shift And using: n=$1; shift in bash and zsh: the value of n is lost after the shift is executed in the first example. But both have the ...
1
vote
3answers
54 views

Bash script to replace some words present in one file from another file

I have two files, one, file1 is 1000 lines with router configurations in it. A portion of it is like this - ! ipv6 prefix-list CCAV6 seq 5 permit 2217:AB23::/40 route-map DENY-ALL deny 11 ! ip ...
0
votes
1answer
24 views

How to assign variables associated with list of ranges to another table with integers

I have a list of integers from 1 to 6k, and I have a list of ranges (start/stop) with a third value I'd like to assign to each integer within those ranges. The list of ranges might look like this, ...
1
vote
1answer
52 views

How to selectively remove columns and rows with bash?

I currently have a data set that looks like this: INPUT Hybridization REF TCGA-FA-8693-01A-11D-2399-05 TCGA-FA-8693-01A-11D-2399-05 TCGA-FA-8693-01A-11D-2399-05 ...
1
vote
0answers
25 views

How to conditionally evaluate if an expression is equal to 0 in bash [duplicate]

I am parsing lines from the output of a command (suppose it's just called "cmd"), where the the first line and every next odd-numbered line is a filename, and every even-numbered line is a string for ...
1
vote
1answer
34 views

Capture text between curly braces in C preprocessed file

I'm working with a preprocessed C source file. I want to extract one function for additional processing. I can find the start of the particular function with: gcc -DNDEBUG -march=native -E source.c ...
0
votes
1answer
40 views

Is the shell created by `bash -i -c <command>` interactive?

From http://unix.stackexchange.com/a/276611/674 When bash is run with -c, it is considered a non-interactive shell, and it does not read ~/.bashrc, unless is -i specified. So, $ type cp cp ...
2
votes
2answers
112 views

bash source script.sh with exit 0

I use a lot of external files in my scripts. But I have a problem, that if I source a file with exit in the contents of the file, the script exits from loading and the strings that I want to use are ...
0
votes
4answers
100 views

How to run subshell commands over SSH?

I have a cluster of computers which are connected via passwordless SSH and I have written a utility which runs a command over the entire cluster. The way it does it is by picking up machines present ...
0
votes
1answer
25 views

Why does bash complain “!”: event not found"? [duplicate]

Running echo "Hello world!" in bash: # echo "Hello world!" -bash: !": event not found Why does bash complain "!": event not found"? No !, everything is OK: # echo "Hello world" Hello world ...
2
votes
1answer
21 views

Exporting a variable so it appears in a script sourced through sudo

I have a bash script/s which has a "main" script which is run as sudo. Variables are declared in this script. Then it sources another commands.sh script, however this script uses sudo to drop back to ...
2
votes
1answer
43 views

Change to a directory containing a space

I'm using a MacBook with OS X installed. I'm on Terminal trying to go to a directory. So I'm in Home and I use the command ls and there is a VirtualBox VMs directory. But when I try to do cd ...
3
votes
1answer
106 views

curl outfile variable not working in bash script

Attempting to shorten a bash script that uses curl to fetch multiple API calls takes something like this: curl --user $USER:$PASS https://api.example.com/foo -o 'foo.json' curl --user $USER:$PASS ...
0
votes
3answers
72 views

bash -c and noninteractive shell [duplicate]

From http://unix.stackexchange.com/a/276611/674: When bash is run with -c, it is considered a non-interactive shell, and it does not read ~/.bashrc, unless is -i specified. How is a ...
0
votes
1answer
69 views

Bash script as bin file installer

I have a package that comes in 2 parts - a bin file and digital certificate. This is to be distributed out to Linux sysadmins to install on RHEL systems in the enterprise. The bin file has various ...
6
votes
1answer
65 views

Standard subshell vs command-substitution subshell

Please explain these trap outputs: $ line(){ echo -------------; echo $BASHPID; } $ trap 'echo bye' EXIT; trap -p; line; (trap -p; line); echo "$(trap -p; line)" trap -- 'echo bye' EXIT trap -- '' ...
0
votes
4answers
64 views

grep all strings that start with a certain char, and finish with another char

I need to grep all strings that start with "[" and finish with a certain string, e.g. "apal". So all chars in between these 2 chars would be shown as well. Given an input such as: ...