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

0
votes
1answer
32 views

Vim saved file not updating on webpage

I am attempting to update an HTML file on my server, but when I do so it doesn't appear to be updating, but rather, serves an old copy instead. I went through the usual process of pressing :w and ...
1
vote
1answer
44 views

Creating a complex variable content by hand

I am creating a shell script dynamically and sending it to a remote server for execution. All is working except when I try to inject a variable with content coming from a file with multiple lines, ...
0
votes
0answers
27 views

What is the meaning of :- in unix? [duplicate]

Trying to understand the existing script where they have assigned ${3:-} to variable. Script : partition_parameter=${3:-} if [ -z $partition_parameter ]; then readonly drop_partition=false ...
1
vote
4answers
86 views

Dangers of using rm command with variables

I am creating a crontab that compresses 15 minute clips from my security camera into one file (24 Hours Long) and then having the clips delete. avimerge -o /media/jmartin/Cams/video/Full_$(date +%F ...
1
vote
1answer
18 views

CentOS - change the password of GPG file by bash script

I am looking for a bash script which input is the old and the new password for changing password of a *.gpg file. I encrypted a txt file with command gpg -c. System create a file.txt.gpg. How can I ...
1
vote
1answer
25 views

How do I both censor a command away from .bash_history and also be able to return to it with up arrow?

When one prepends a space character to the command, it disappears from history. But this also causes the command to no not easily editable and re-runnable. How do I make weaker version of ...
1
vote
3answers
33 views

Find position of matched word in a line in bash (not position of character)

I have a line like Xckt VDD VSS sig[1] sig[2] sig[3] sig[4] sig[5] sig[6] CKT and I want to find the position of sig[4] in the line. In this case it should return 7. I wanted some simple script/ ...
1
vote
1answer
47 views

BASH Variable checker function

I am struggling to figure out a way to reduce code duplication. Specifically when checking if a variable is set. My code currently looks like this: # webadmin enabled if [ -f "${servercfgfullpath}" ...
0
votes
2answers
94 views

Why does `read` not pick up all my vars?

My apologies for the very basic question, but can someone please help explain why the following does not print 3 2 1 6 5 4? echo '1 2 3 4 5 6' | while read a b c; do echo result: $c b a; done ...
0
votes
0answers
53 views

Executing remote code with arguments

Why this: ssh -i ~/.ssh/master.pem ec2-user@xx.xx.xx.xx 'bash -s' < `dirname $0`/elements/"$element" returns hostname.sh test-5000: No such file or directory when $element is not a just a single ...
1
vote
3answers
137 views

Do the two styles of for-loops differ in what they can express?

There are two styles of syntax of for-loop: for (( expr1 ; expr2 ; expr3 )) ; do commands ; done for name [ [in [words ...] ] ; ] do commands; done At a glance, the kinds of looping that two can ...
1
vote
1answer
69 views

Can the command within for-loop affect the iterations?

In Bash, the syntax of the C-like for-loop is: for (( expr1 ; expr2 ; expr3 )) ; do commands ; done Can the execution of commands affect the evaluations of the three arithmetic expressions ...
1
vote
4answers
44 views

Using cut to return the middle of a string

I have an xml string echoed to stdout along the lines of <xml:attribute>{41c33a-4893b-3627a-617a}</xml:attribute> I want to return the string {41c33a-4893b-3627a-617a} in this case. I ...
-1
votes
1answer
33 views

Arithmetic expressions in for-loop

In for (( expr1 ; expr2 ; expr3 )) ; do commands ; done expr1, expr2, and expr3 are arithmetic expressions. Is expr1 ; expr2 ; expr3 not an arithmetic expression? (( expr1 ; expr2 ; expr3 )) ...
1
vote
1answer
37 views

Is there a standard abbreviation for 'find . -name foo' or do I need a function for this?

I recently used find . -name some-file-name a lot and decided that it's time to abbreviate this with a function (fb stands for find below): function fb() { find . -name "$1" } This seems to work ...
0
votes
3answers
49 views

Comparing integers: arithmetic expression or conditional expression

In Bash, two integers can be compared using conditional expression arg1 OP arg2 OP is one of ‘-eq’, ‘-ne’, ‘-lt’, ‘-le’, ‘-gt’, or ‘-ge’. These arithmetic binary operators return true if ...
0
votes
2answers
49 views

What's the difference between using shell command (e.g. foo) directly and using $(foo)?

I get confused about using command directly and using $(foo). I'm using Mac, I try to list apps which is install by brew cask(a package manager), and echo each app. I have two short Shell scripts, ...
1
vote
1answer
29 views

Arithmetic expansion and parameter expansion

$ x=foo; foo=bar; bar=6; $ echo $x foo $ echo $((x)) 6 why can the arithmetic expansion trace from variable x to its value foo, from variable foo to its value bar, and then from variable foo to ...
3
votes
1answer
146 views

Variables of integer type in Bash?

There are two ways to define and use variables of integer type in Bash declare -i a new variable use a variable in an arithmetic expression, without declaring it. My questions: What are the ...
0
votes
1answer
34 views

Create HISTFILE in subshell

Here is my HISTFILE: $ echo $HISTFILE /home/Steven/.bash_history I can create it by using exit: $ [ -e $HISTFILE ]; echo $? 1 $ exit $ [ -e $HISTFILE ]; echo $? 0 However if I exit a subshell, ...
0
votes
0answers
9 views

Converting c++ to bash, need to know if a specific variable has bash significance [migrated]

I am converting a c++ code to bash for several reasons, one being that I only know bash aside from what I've been learning while doing this conversion! There's a variable (let's call it "size") that ...
11
votes
3answers
547 views

How can I work with binary in bash, to copy bytes verbatim without any conversion?

I am ambitiously trying to translate a c++ code into bash for a myriad of reasons. This code reads and manipulates a file type specific to my sub-field that is written and structured completely in ...
0
votes
1answer
40 views

Loops: for vs while… beyond the basics. Subtle differences/pros/cons for my code? [closed]

I have been writing/refining a relatively complex code for the past year, and learning bash along the way. My code is filled with functions that have complex multi-level while loops. I've recently ...
3
votes
1answer
56 views

Bash script - auto complete for user input based on array data

In a bash script I'm reading some user input with read. Now I want to provide the possibility to auto-complete the input by hitting the Tab key. Easy example: Let's say, the user shall type in a name ...
0
votes
1answer
28 views

Simple BASH script treating flags as commands

I've been trying to write a really simple bash script as follows: #!/bin/bash gcc –Werror –std=c99 client.c –o client gcc –Werror –std=c99 server.c –o server Each of the commands works fine when ...
0
votes
0answers
20 views

What is the difference between `<subcommand>` and $(<subcomand>) in bash? [duplicate]

What is the difference between `<subcommand>` and $(<subcomand>) in bash ? For example, these two commands seems equivalent: me@host:~$ export `echo 'a'`=42 me@host:~$ echo $a 42 ...
3
votes
3answers
35 views

How to pass array to bash shell script?

How do I pass an array as a variable from a first bash shell script to a second script. first.sh #!/bin/bash AR=('foo' 'bar' 'baz' 'bat') sh second.sh "$AR" # foo sh second.sh "${AR[@]}" # foo ...
0
votes
1answer
38 views

Using Named Pipes in Bash created in a C Program

I have a C code that takes a rather large input. At every iteration, it processes a small chunk of it and it should send that processed chunk to S3 using curl. In the end, it will generate a number of ...
-2
votes
1answer
39 views

Is a string an arithmetic expression?

In Bash, I use a string where an arithmetic expression is expected: $ (( hello )) $ echo $? 1 $ echo $(( hello )) 0 $ let aaa=hello $ echo $? 1 $ echo $aaa 0 There is no error reported. So is a ...
3
votes
1answer
30 views

mkfifo pipes, file descriptors and ImageMagick (convert)

I'm in trouble using named pipes (i.e. created with mkfifo) and file descriptors to redirect outputs and grab inputs to/from them within ImageMagick (convert). Basically, with the following bash code ...
2
votes
1answer
25 views

Bash shell script program that prompts for and reads two integers from the user.

Okay, so I been trying to figure this problem for a while and I'm coming up with errors left and right. This is my first time trying to learn the basics. So any advice would be helpful! Problem: I'm ...
0
votes
0answers
16 views

Reversing letters [duplicate]

I want to basically reverse some letters. I have this: a b c and I want this: c b a Right now I have this code that prints the first a b c A=$@ for i in $A ; do echo "$i" done Any help is ...
2
votes
2answers
55 views

Accessing array index variable from bash shell script loop?

I want to access the array index variable while looping thru an array in my bash shell script. myscript.sh #!/bin/bash AR=('foo' 'bar' 'baz' 'bat') for i in ${AR[*]}; do echo $i done The result ...
0
votes
2answers
74 views

Error when eval a for-loop

I am writing a script which accepts two arguments: #! /bin/bash eval for i in {$1..$2}; do echo $i; done I run it like: $ ./myscript 0002 0010 syntax error near unexpected token `do' Why is ...
0
votes
1answer
42 views

Crontab task not trigerred

I am trying to automate backup management on server on raspberry and put a regular tar triggering into a crontab. I set it up via bash scripts. First I set up the task and then use script to carry out ...
1
vote
1answer
30 views

Join two files in a batch mode

I have many files with the following names: 0001mm.xyz , 0002mm.xyz , 0003mm.xyz ... 0001qm.xyz , 0002qm.xyz , 0003qm.xyz ... I want to join the contents of 0001mm.xyz and 0001qm.xyz ...
-3
votes
0answers
26 views

Checking for sequence of numbers received through stdin in a loop using shell script?

I have a pipe line like this: foo | bar | baz (shell script?) The bar program sends through the pipe to baz a string formed like this: Code: 1 Code: 2 Code: 3 I want to cut "Code" part, collect a ...
-2
votes
3answers
31 views

Assignment: expression or command?

In Bash and Posix shells, there are many forms of commands, and an assignment is a form of command (specifically a simple command) if I am correct. However let can be used in front of an assignment, ...
1
vote
1answer
34 views

/bin/bash No such file or directory Connection closed [closed]

I try to connect to a server using ssh (authentification is fine). I got this: /bin/bash: No such file or directory Connection to xxx closed. Before, everything is working fine, Until I have ...
-2
votes
2answers
75 views

Why does command not work with a command beginning with assignment?

From Bash Manual: command [-pVv] command [arguments ...] Runs command with arguments ignoring any shell function named command. Only shell builtin commands or commands found by searching ...
0
votes
0answers
13 views

searching through command line history [duplicate]

I use reverse search when looking for a particular command on the command line by pressing CTRL + R. That returns the first command it finds in reverse order. To go back to the next further command I ...
3
votes
2answers
63 views

Changing a file's modified date based on date in file name

I have a directory full of photos with file names in this format: IMG-20160305-WA0001.jpg. The date taken is obviously in the file title. Unfortunately the date modified on all files is today. I ...
0
votes
0answers
14 views

Script to hard-link copy new files in a source directory? [duplicate]

I am using Emby's media auto-organize feature. This features takes a watch folder and moves the media to the appropriate directory. It's not perfect so sometimes it moves the media to the wrong ...
0
votes
2answers
40 views

List Most Recent File per Sub-Folder

I have a File structure of : FOLDER/SUB_FOLDER/Text_File I have over 1k+ FOLDER and each FOLDER has at least 2 different SUB_FOLDER with each SUB_FOLDER their own Text_File. I'm trying to ...
0
votes
1answer
38 views

Why does parameter expansion happen before brace expansion in this example?

From http://unix.stackexchange.com/a/7739/674, why does parameter expansion happen before brace expansion in the following example? eval rm foo.{$ext0..$extN}
1
vote
1answer
41 views

Aligning Hexdump Data in a Specific format?

I am reading serial data from my Raspberry Pi and all I am doing is a Hexdump I have to find the header and then go to the 2nd byte of data from header for ex: ed 13 74, I have to take the value 4 , ...
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
40 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);} ...