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

5
votes
4answers
7k views

Constantly check if file is modified bash

I have a file called file1 I want in a script, whenever there is a change in it, do something, a beep sound actually. How do I do that ¿? Thank you in advance
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 ...
86
votes
5answers
64k views

Why doesn't my Bash script recognize aliases?

In my ~/.bashrc file reside two definitions: commandA, which is an alias to a longer path commandB, which is an alias to a Bash script I want to process the same file with these two commands, so I ...
0
votes
4answers
63 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: ...
0
votes
1answer
33 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, ...
3
votes
3answers
2k views

Query list of servers for memory/cpu allocated

Running RHEL 6.2, trying to write a bash script to SSH to a list of remote servers, and write the CPUs and Total Memory to a file, one line per host in the following format: HOSTNAME1 CPUS: 12 ...
3
votes
1answer
145 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 ...
-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
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 ...
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 ...
-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 ...
0
votes
1answer
35 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 ...
0
votes
2answers
73 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 ...
3
votes
3answers
34 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
27 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 ...
1
vote
1answer
29 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 ...
11
votes
2answers
26k views

How to move a file without preserving permissions

The problem is I want to be able to see errors when moving a file, but not see errors with permissions problem. In other words - I care if the file is not fully transmitted, but don't want to see ...
3
votes
1answer
27 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 ...
7
votes
2answers
221 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). ...
2
votes
1answer
24 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 ...
2
votes
2answers
54 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
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 ...
1
vote
1answer
30 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
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, ...
0
votes
1answer
766 views

Download yad with bash script

i'm building a simple deb package (single binary) for a little project i've been working on. Now I want to build a nice interface around it and used zenity for a couple of times, but this time I ...
-3
votes
0answers
25 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 ...
3
votes
2answers
62 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 ...
56
votes
6answers
155k views

What is the “eval” command in bash?

What can you do with the eval command? Why is it useful? Is it some kind of a built-in function in bash? There is no man page for it..
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}
4
votes
3answers
945 views

How do I let bash autocomplete wildcards?

If I have directory containing the files foo.bar.a.cat foo.bar.a.hat and I type ls f+TAB the bash shell autocompletes to ls foo.bar.a.. If I type ls *bar*+ TAB I would like it to autocomplete to ...
70
votes
4answers
21k views

What is the difference between “&&” and “;” when chaining commands

What is the difference between the following methods of chaining commands? cmd1; cmd2 cmd1 && cmd2
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
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 ...
0
votes
3answers
51 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: ...
4
votes
5answers
422 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
7answers
481 views

Matching n letter filename with ls

I am using the ls command in bash, trying to find all files or directory of length n. Let's say n=5 My command is: ls ????? But this would also include characters that are non letters such as ...
0
votes
0answers
28 views

Plink never return to command line [closed]

I'm trying to use plink to execute command from file. So I use it this way: plink -ssh user@host -pw pass -batch -m "path_to_script" But unfortunately plink never return to terminal. I also tried ...
-7
votes
0answers
37 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
24 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 ...
14
votes
5answers
26k views

Script to change current directory (cd, pwd)

I want to run a script to simply change the current working directory: #!/bin/bash cd web/www/project But, after I run it, the current pwd remains unchanged! How can I do that?
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 ...
0
votes
2answers
2k views

VLC script on ubuntu server

I need a small script which run three vlc command on the same time (on Ubuntu server 14.04) as stated below: #!/bin/sh cvlc -vvv v1 --sout ...
-1
votes
2answers
41 views

How to convert a string into a date in a given format

Need a string in '9-2-1832' format in a '1832-09-02' format. Must be able to fill a 'date' type field in mysql.
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 ...
2
votes
2answers
35 views

Switch user to root and run execute the rest of the script

I need help in changing the user to root and run the rest of the commands as root in shell script. Please help me do that.
2
votes
1answer
501 views

How to use history commands with readonly PROMPT_COMMAND?

I'm sometimes logged in on a host which I do not control and where PROMPT_COMMAND is readonly. Is there some way to work around this to run history commands anyway, for example using PS1? I've tried ...
-1
votes
2answers
44 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
2answers
132 views

Daemonize a process in shell?

http://linuxg.net/how-to-transform-a-process-into-a-daemon-in-linux-unix/ gives an example of daemonizing a process in bash: $ nohup firefox& &> /dev/null If I am corrrect, the command ...