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

2
votes
3answers
12k views

I get “bash: …: No such file or directory” even though the executable is there [duplicate]

Operating system: Lubuntu 13.10, 64-bit. I installed the Seamonkey browser from http://www.seamonkey-project.org/ following the instructions quoted below from http://www.seamonkey-project.org/doc/...
8
votes
4answers
15k views

Pipe assigns variable

For simplicity I would like to do: echo cart | assign spo; echo $spo Output: cart Does such an assign application exist? I am aware of all the ways to do this using substitution.
1
vote
1answer
1k views

How to insert a 'string+ file name' in the file text in commnad line bash shell?

I am working on a problem, As part of that I have got some 30,000 files with some content in it. What I want is that I want name:filename inside the file text, but since I have got so many files, it ...
3
votes
1answer
12k views

Appending to same array in various loops, only last values remain Bash 4

I have something like this: FILES=() for i in *.map do FILES+=($i) done find /var/candy -name "chocolate_[0-9]" | while read snack do FILES+=($snack) done for file in ../out/amsterdam/...
0
votes
1answer
2k views

file path in variable from user input

I'm trying to create script where user will give path to some file, and script will check if file exists and do some stuff... I've wrote this code: read -p "Enter path: " $path #check if path is not ...
2
votes
1answer
3k views

Automatically save bash command history in screen session [duplicate]

I connect to a screen session. After doing some stuff I detach it. Then in history | tail I only see screen -r and previous commands and not the commands run in screen session. Basically history shows ...
0
votes
2answers
444 views

Bash newline doesn't print

I would like to output results in latex table format using a bash script. However, when I want to add a newline symbol, bash either prints it (\n) or doesn't add a newline. I already tried several ...
5
votes
2answers
12k views

Running thousands of curl background processes in parallel in bash script

I am running thounsand of curl background processes in parallel in the following bash script START=$(date +%s) for i in {1..100000} do curl -s "http://some_url_here/"$i > $i.txt& ...
3
votes
1answer
549 views

Why doesn't this regex work?

I want to look at the output of git status -s to determine whether there are any untracked files in the tree. I tried the following test, but the regex doesn't match. Why not? $ git status -s ## ...
1
vote
1answer
362 views

How to globally enable all of Gentoo's bash completions at once?

eselect bashcomp enable unfortunately seems to lack a --all option, and I certainly don't want to manually activate each of the 194 entries. Can this be automated somehow, and set up such that ...
15
votes
2answers
20k views

What do square brackets mean without the “if” on the left? [duplicate]

As far as I know, square brackets are used to enclose an expression usually in if else statements. But I found square brackets being used without the "if" as follows: [ -r /etc/profile.d/java.sh ] &...
2
votes
1answer
315 views

Why does \033 escape work for vars like PS1 and \x1b doesn't?

According to the documentation of echo builtin, (as well as printf), \033 and \x1b should both translate to the same ASCII control code (Esc, which is decimal 27). While both \x1b and \033 work the ...
5
votes
2answers
1k views

Can I set a bash timeout only for virtual consoles (ctrl+alt+{f1-f6})

I know that I can set a TMOUT variable to automatically end a bash session after a specified period of inactivity. However, what I want is to apply that only to my 6 built-in virtual consoles, which ...
2
votes
2answers
3k views

How to sum a bash array of numbers (some in scientific notation)?

Since the following command using bc does not work for numbers in scientific notation, I was wondering about an alternative, e.g. using awk? sum=$( IFS="+"; bc <<< "${arrValues[*]}" )
2
votes
3answers
136 views

What is the language that appears on the first line of a script? [duplicate]

Bash scripts start with the following line #!/bin/bash # Rest of script below ... In bash the # character is the start of a comment, but #!/bin/bash is definitely not a comment, therefore it isn't ...
15
votes
3answers
17k views

ASCII binary tools?

Which is a good tool to convert ASCII to binary, and binary to ASCII? I was hoping for something like: $ echo --binary "This is a binary message" 01010100 01101000 01101001 01110011 00100000 ...
0
votes
2answers
376 views

How can I know my job number when I executing a COBOL program through a shell script

How can I know my job number when executing a COBOL program through a shell script?
0
votes
1answer
446 views

Can't create a minimal chroot jail

Was trying to create a minimal chroot jail. The steps followed was: Created a folder chroot Copied bash to the folder chroot Run ldd bash to know the dependencies ldd /bin/bash linux-vdso.so.1 =&...
4
votes
3answers
3k views

How do I create a bash script that sums any number of command line arguments?

How would I create a bash script that the user can use to sum any amount of command line arguments? For example, say my script is called sum: sum 3 3 sum 3 5 8 sum 9 8 21 38 And so on.. I ...
0
votes
1answer
40 views

How do I display contents of a file where PATH environment changes are made?

Say I change the $PATH environment variable. If I'm asked to display the contents of the file where this change happened, how would I do this?
3
votes
2answers
863 views

Converting Webserver Logged IP Addresses to DNS

I'm trying to use a bash script to process a webserver log file and replace any IP's it finds with their corresponding DNS hostnames. An example entry of a single line from the log file is: <12&...
7
votes
4answers
2k views

How to start a script with clean environment?

I tried the following but it doesn't seem to work: $ cat script.sh #!/bin/env -i /bin/sh /bin/env $ script.sh /bin/env: invalid option -- ' ' Try `/bin/env --help' for more information.
0
votes
1answer
566 views

Why does a working standalone nested function/script not work inside a larger script? [duplicate]

The following (nested) function/s function hpf_matrix { # Positional Parameters Matrix_Dimension="${1}" Center_Cell_Value="${2}" # Define the cell value(s) function hpf_cell_value { ...
3
votes
2answers
2k views

How do I redirect only stderr?

I am having a bit of trouble doing this. I am required to run a compiled .java file and redirect only stderr to a file called error. So the .java file is named javaProgram.java. This is what I have ...
3
votes
3answers
762 views

counting chars using bash

I'm quite new to bash, and I'm trying to count the number of chars in a file. I wrote the following function: function chars(){ m=$(cat $1) m=${#m} echo $m } calling it with echo $(...
2
votes
3answers
2k views

Does bash recognize a variable declaration as string if you do not put the quotation marks?

name=Jackson echo $name This will display Jackson. name="Jackson" echo $name This will also display Jackson. So I assume by putting quotation marks around a variable it is making it a string. ...
3
votes
3answers
203 views

How to execute a script on program launch and end

As the title suggests - how do I run a script when a program starts/ends? Specifically, I made a script to toggle my touchpad/trackpoint on and off and I want to use it to turn inputs off when I ...
10
votes
3answers
429 views

bash: Some issue when using read <<<“$VARIABLE” on a read-only root partition. Any known workarounds?

Just by coincidence I had to use my ATA-ID-to-device-name script (found here: http://serverfault.com/questions/244944/linux-ata-errors-translating-to-a-device-name/426561#426561) on a read-only / ...
3
votes
3answers
17k views

Insert text in specific lines of a file?

How can insert some text in specific lines of a file? What is most simplest method that I can use? (bash, sed, awk?) What I want to do, might be simple, but I don't know where I should start. It's ...
1
vote
1answer
66 views

bash script var not changed after the loop [duplicate]

I'm quite new to bash scripting, and I wrote the following script to emulate the wc -c command: (I know it doesn't count the end of the line) #!/bin/bash echo $1 len=0 cat $1 | while read line do ...
0
votes
4answers
981 views

Unset http_proxy enviroment variable

Updated 11/03: After doing some test with your suggestions, I only can be sure about one thing: there is something related to the graphical environment, because if I login through ssh or using a ...
4
votes
1answer
410 views

echo $? returning 0 instead of 1

[root@server ~]# bash << eof > cat adsfasdf > echo $? > eof cat: adsfasdf: No such file or directory 0 Could anyone please explain why it is returning exit status 0 instead of 1?
2
votes
0answers
157 views

Segmentation fault with dialog [closed]

I'm getting a segmentation fault with the following script when it's more that one child dir past the pwd. The program kills with the error message and I have to reset the shell. For example: I start ...
1
vote
2answers
337 views

How to use `ls` to group and show only a first word of directory name?

I want to define a new ls command to do something like this The first when i use ordinary ls command: $ls undergrade.AI undergrade.KDD undergrade.AI2 undergrade.micro ...
-2
votes
1answer
111 views

What does readonly mean or do?

What does readonly mean or do in this case? I have never seen or heard of it. a="testString"; b=a; readonly b; b=25; Also, would the final value of b at the end be 25?
1
vote
1answer
4k views

Run an executable with a Shell Script

I have mplayer installed and I want to create a simple shell script that runs in bash and executes mplayer * in the current directory. So, how to call upon mplayer in the shell script? I am a newbie ...
5
votes
1answer
1k views

Bash capture any error like -e but don't exit, do something else

I want to set a flag in a shell script (bash) so that if anything returns non-zero, a flag is set (i.e. set a variable like errors="True"). So far, I've thought of calling the script with ...
3
votes
1answer
136 views

How can I get Bash to display the auto-completion definitions for a given command?

I use module command to load and unload stuff to my environment, some of the machines I use have proper auto-completion others do not. I'm wondering if I it possible to know where the completion ...
2
votes
1answer
540 views

Exiting a Bash script when a sudo child quits

I'm trying to launch a couple of sub-programs from a bash script and then wait on either of them to quit before quitting the other and exiting the script. CMD1PID= CMD2PID= exit_trap () { ...
2
votes
2answers
104 views

scripted pdf code review

What I try to achieve I need to review a bunch of C source code spread out into dozen of directories. I already have a bash script which does the following: It searches for all source codes in the ...
0
votes
1answer
451 views

from iostat -En output ,i need to display Hard Error more than 2

I am a Customer service engineer for solaris. But I am new to shell scripting, I need to display the lines which are having Hard Errors more than 2 from the output of iostat -En | grep Hard in case of ...
0
votes
1answer
4k views

Trying to cp a path with spaces, fails when scripted but echoing and pasting succeeds? [closed]

I have a script that is trying to copy a directory from a path that includes backslash-escaped spaces and is stored in a string variable to a subdirectory of the working directory. When I run the ...
2
votes
1answer
94 views

Using 'convert' with files that has space characters?

for f in $(ls mydir/*.jpg) do convert -thumbnail $size -quality $quality $f thumbsdir/$(basename $f) done I'm trying to code a script that takes a directory with images and generates thumbnails ...
3
votes
1answer
620 views

bash environment - pasting strings with “special” characters

I'm using an application and I need to paste a string into the app... e.g ãµÜÇæ¢üäÄøqò When I login with bash shell it's impossible to paste the string with the special characters. If I change the ...
6
votes
4answers
792 views

How do I stop bash from hanging when trying to start programmes while NFS is disrupted

I am currently experiencing a bug in Ubuntu 13.10 which means that when I resume my machine after a suspend, the network connections do not come back up. I have a couple of NFS mounts and because they ...
3
votes
3answers
1k views

Adding prefixes/suffixes to file names without typing it all over again?

I would like to do something like the following $ tmp=name* $ mv $tmp new_$tmp $ ls new_* $ new_name-with-stuff-i-dont-want-to-type name-with-stuff-i-dont-want-to-type Setting the environment ...
6
votes
1answer
459 views

Change the location of .bashrc

Is it possible to change the location of .bashrc from /home/orhanc/.bashrc to some other directory?
2
votes
2answers
412 views

What is the use of “&>>” in bash?

I was studying a bash script code where I encountered operator "&>>". I didn't understand its use. So, I referred to http://www.gnu.org/software/bash/manual/html_node/Redirections.html . It is ...
5
votes
2answers
940 views

Why does Bash history not record this command?

The command printf "#!/bin/bash\n" > t generates an error(bash: !/bin/bash\n": event not found), but hitting the up key does not recall the command so that I can modify it. Why is that? (What I ...
2
votes
3answers
130 views

How to create a function based on commands not defined yet?

I have some scripts (that are out of my control) that loads some environment settings to my session. So whenever I want to load I have to execute a series of commands: export SOME_VAR=/path/to/main/...