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
593 views

Modify XML file based on partial name

I've been using Xmlstarlet to modify some .xml files but I am lost trying to figure out how to modify a tag based on a partial name. What is the best way to comment out an entire line that begins ...
5
votes
2answers
1k views

How to check if EDID can be tusted

read-edid gives me the message "The EDID data should not be trusted as the VBE call failed". Thats okay, but I want to find out, that this data is not reliable, another way, because I can't use ...
3
votes
3answers
3k views

Why do 'ssh host echo $PATH' and printing the $PATH after ssh'ing into the machine give different results?

On a particular host, when I ssh into the machine and enter echo $PATH I get /home/wxy/bin64:/home/wxy/bin:/usr/kerberos/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/bin:/usr/bin and if I ...
7
votes
7answers
13k views

How to test whether the file is crlf or lf without modyfing it?

I need to periodically run a command, that ensures that some text files are kept in linux mode. Unfortunately dos2unix always modifies file, which would mess file's and folder's timestamp and cause ...
8
votes
3answers
288 views

Split an existing prompt command line in a few lines

I understand I can type \ enter at the end of a bash command line to continue that command in another line. But how can I split a prompt command line — that has already been fully typed — into two? ...
1
vote
2answers
715 views

Augeas in shell script

I'm trying to use augtool in shell script ex: #!/bin/bash augtool <<-EOF print /augeas/load EOF However if I execute this script, the script will run indefinitely with no output and the CPU ...
0
votes
2answers
23k views

“not a valid identifier” when I do “export $PATH”

When I run export $PATH in bash, I get the error not a valid identifier. Why?
6
votes
2answers
2k views

How to trigger error using Trap command

I am using Ubuntu 12.04.2. I am trying to use "trap" command to capture abnormal or error in my shell script but I am also trying to manually trigger "Error" exit. I have tried exit 1, but it won't ...
3
votes
4answers
778 views

Shell: How do I get the last argument the previous command when it was detached?

Within the shell, typing ALT+. or using !$ recalls the last passed argument of the previous command. I use this all the time, but how do you do that when you detached the previous command? $ ...
4
votes
3answers
353 views

Use bash history file from old machine when setting up new machine?

I love my bash history. Sometimes I've issued really long commands and I really depend on my bash history to get them back quickly. I've increased my history size with: HISTSIZE=100000 ...
30
votes
2answers
2k views

Symbolic link recursion - what makes it “reset”?

I wrote a little bash script to see what happens when I keep following a symbolic link that points to the same directory. I was expecting it to either make a very long working directory, or to crash. ...
0
votes
0answers
441 views

Easy way to push data into MongoDB from Bash shell script?

I know you can create a Javascript file that the MongoDB shell will execute upon startup. But I'm hoping for something more "lightweight" than that. I am using a Linux program that has a scripting ...
10
votes
2answers
4k views

Executing piped commands in parallel

Consider the following scenario. I have two programs A and B. Program A outputs to stdout lines of strings while program B process lines from stdin. The way to use these two programs is of course ...
-1
votes
1answer
367 views

SED command and filenames with space

I was hacked, for my php files was infected. Example: http://www.nwww.ma.mk/oscommerce/configweb/apexfash-wp-blog.txt Bad Code: <?php ...
0
votes
2answers
186 views

Why are there empty lines in the output of my command?: find ~/x/y/ | shuf > ~/Desktop/z.txt

As it turns out the reason for this problem was one filename with several newlines. (No idea how that happened.) find ~/x/y/ | shuf > ~/Desktop/z.txt This command works pretty much as expected ...
0
votes
1answer
392 views

MAC bash commands stop working properly

I was trying to install some stuff for scala development on my MAC, and probably I managed broke the shell/terminal while I was mindlessly running some scripts that I don't know. Now when I start the ...
1
vote
2answers
1k views

for loop to get more than one arguments

In python and some other programming languages, it is easy to get a vector instead of one variable everywhere and in loops. like python: for variable in ...
4
votes
2answers
778 views

Convert MAC address to Link-local address with bash

How can I convert a Mac address into an ipv6 Link-Local address? you have to add fe80:: at the start and insert ff:fe in the middle furthermore all leading zeros must be stripped
0
votes
2answers
526 views

search fitting ipv6 address for MAC-Address in neighbours

I have a list of possible to ip6 addresses converted MAC-addresses, that could be found in the output of ping6 ff02::1%wlan0 possible mac addresses are for example: 66:70:02:75:80:fe, ...
4
votes
2answers
7k views

how to loop through arguments in a bash script

I would like to write a bash script with unknown amount of arguments. How can I walk through these arguments and do something with them? A wrong attempt would look like this: #!/bin/bash for i in ...
13
votes
3answers
574 views

When to use redirection to stderr in shell scripts

I know that well-behaved utilities like grep output "normal" messages to stdout, and error messages to stderr. $ grep '^foo' file1 file2 file1:foo grep: file2: No such file or directory When I'm ...
0
votes
2answers
4k views

Expect script within bash & exit codes

I have a bash script that calls an expect script. The expect script has several conditions. It ssh's into a box and executes a command, and there are different possible errors that could happen which ...
13
votes
5answers
23k views

Test if there are files matching a pattern in bash

I am trying to write an if statement in bash to test whether there are any files matching a certain pattern. If there is a text file in a directory it should run a given script. My code currently if ...
2
votes
2answers
224 views

Color PS1 based on previous command output [duplicate]

I have my current PS1 as follows. The $? output is really useful (second line). export PS1="\ ${PSOn_Blue}${PSBWhite}\t\ ${PSColor_Off} \$?\ ${PSColor_Off}${PSBGreen} \u\ ${PSColor_Off}${PSWhite}@\ ...
10
votes
4answers
1k views

How do I trigger autocomplete without a tab key?

I'm ssh-ing to my machine using my iPhone with an app called ServerAuditior. It doesn't have tab key. See screenshot. How do I trigger autocomplete without the tab key? I don't want to type a lot of ...
9
votes
2answers
3k views

How to export variables that are set, all at once?

set command displays all the local variables like below. How do I export these variables all at once? >set a=123 b="asd asd" c="hello world"
1
vote
2answers
3k views

How to export variables from a file?

tmp.txt file contains the variables to be exported, for e.g. a=123 b="hello world" c="one more variable" How to export all these variables using export command, so that, they can later be used by ...
6
votes
2answers
2k views

How can I fix this SSH hostname tab completion script?

I found the following script (for bash) that enables me to get tab completion for any hostname I've connected to (from ~/.ssh/known_hosts): complete -W "$(echo `cat ~/.ssh/known_hosts | cut -f 1 -d ' ...
7
votes
1answer
474 views

What are the readline word separators?

When I delete a "word" in Bash, it will stop at certain characters like _ and /. For example, if I type /foo/bar and activate backward-kill-word (typically mapped to Alt-Backspace and/or Ctrl-w), ...
2
votes
1answer
997 views

AWS XML response error signature does not match

I have a bash script that should return the XML response for AWS EC2 regions but I am getting an XML error response as: "SignatureDoesNotMatch" The request signature we calculated does not match the ...
5
votes
2answers
872 views

Quoted vs unquoted string expansion

for i in $(xrandr); do echo "$i" ; done for i in "$(xrandr)"; do echo "$i"; done for i in "$(xrandr)"; do echo $i; done I understand why 1 differs from 2. But why does 3 give a different output ...
6
votes
9answers
19k views

Bash way to check if a process is already running in the background (and skip re-execution based on that)?

Can I make a bash command line that only runs a certain command if the process is not already running (in the background)? How do I check*, if a command is already running? (so I can add the next ...
4
votes
2answers
6k views

How can I rename all files with one extension to a different extension recursively [duplicate]

Say I have a folder: / /a.bub /v.bub /dr.bub /catpictures /catpictures/or.bub /catpictures/on.bub How can I format a script to change each of these to .aaa. Here is what I've got, although it ...
2
votes
1answer
287 views

Prompt user for sentence and store it without being disturbed by spaces

I have a bash function that prompts user to input certain data. I tried it with first name, last name, birthday etc. Data that is mostly represented in one sentence. When I ask for street + no. the ...
2
votes
2answers
508 views

Debugging bash functions [closed]

So here I have a simple function that I wish to debug. However, I am unable to debug the desired function even with set -o functrace enabled. Before resorting to asking this question, I had managed ...
2
votes
1answer
660 views

better way to get memfree from /proc and convert to decimal [duplicate]

I'm using awesome wm with bashets to make a little text widget to display the free memory. I wanted to convert the number from total kB to gigs (i.e. 1.2). this is what I came up with... ...
-1
votes
3answers
2k views

run file from different directory [closed]

I have a directory mainfolder with a subdirectory execution which contains a configure script. I can switch to the execution directory and run ./configure and it works fine. Now I'm trying to figure ...
2
votes
0answers
34 views

why bash history overlap the prompt when scroll up in the history? [duplicate]

I customized my bash prompt, PS1 value. ~/.bashrc: Color_Off='\e[0m' # Text Reset BGreen='\e[1;32m' # Green BPurple='\e[1;35m' # Purple BWhite='\e[1;37m' # White ...
27
votes
3answers
2k views

Why shouldn't someone use passwords in the command line?

Why do people fear writing passwords in the command line? The history file is located in ~/.history, so it's available only to the user who executed the commands (and root).
0
votes
1answer
99 views

How can I use a variable from a script?

A bash script is running as I defined it in Startup Applications. It is possible to display on terminal a variable used in that script? If yes, how?
5
votes
3answers
20k views

Fix “firefox is already running” issue in Linux

I am trying to open Firefox in CentOS, but I'm getting the following message: Firefox is already running but is not responding and Firefox doesn't open. I tried this in command line: kill ...
3
votes
1answer
979 views

How can I convert this bash function to the fish shell

I'm trying out the fish shell 2.0 to replace bash. I'm trying to convert the following bash function to a fish function, but its giving me hell. I have a several similar functions so if someone ...
4
votes
4answers
7k views

Bash - Multidimensional Arrays and Extracting variables from output

I am trying to do something simple however I'm not sure how to achieve my goal here. I am trying to extract the: USER, TTY and FROM values that are given by the w command on the console. In bash I am ...
9
votes
2answers
10k views

Bash scripting - loop until return value is 0

I need to umount something in my script, but sometimes it unmount's before all of the data has finished being copied and causes the umount to fail. I looked for a way to do a "blocking" umount, but I ...
-4
votes
3answers
201 views

Linux prompt missing brackets

I'm using centos in my VPS server and guest system. There're two logins for a guest system. One is root and one is regular. After I mounted the guest system and chroot to the mounting directory, I ...
2
votes
5answers
9k views

Carriage return issue

I have this in a bash script DAY2="20130605"<Cr> echo "This is yesterday date:"$DAY2"end" Why is the output the following? It seems as though there is a carriage return in DAY2 but where is ...
1
vote
1answer
112 views

How can I write a small log with bash?

I'm running applications via PHP exec with bash. My problem is that this creates large log files. I need only the last ouptut I don't need a log of all activity per second. This is my bash : %s > ...
5
votes
2answers
3k views

Pass arguments to function exactly as-is

I have the following function: bar() { echo $1:$2; } I am calling this function from another function, foo. foo itself is called as follows: foo "This is" a test I want to get the following ...
3
votes
3answers
1k views

How to make my tmux which starts via crontab @reboot use bash?

I have a crontab which launches tmux-launching-script as follows : -sh-3.00# crontab -l @reboot /root/scripts/tmux_autostart.sh where #!/bin/bash # setup tmux session tmux new -d -s my_session ...
0
votes
4answers
2k views

How to do a “if not” in Bash without a test?

I would like to use the return value of a bash function in a 'if not' statement. The following is an example script: #!/bin/bash function myfunction () { if [ $1 = "one" ]; then return 1 elif [ ...