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

0
votes
2answers
32 views

Find all words beginning with Q

How do I search a text file and list all the words begining with Q? The file I am searching is Python source code. The closest I have found to a soulution is this question but that is not what I ...
0
votes
2answers
7 views

Merge (combine) directories using rsync

I need to create deploy script to combine directories ├── LIB_COMMON │ ├── file1.php │ ├── file2.php │ ├── file3.php │ └── file4.php ├── LIB_CZ │ ├── file2.php │ ├── file3.php │ ├── ...
1
vote
1answer
29 views

How can I make the unix `pass` program play nice with `ssh` inside the Linux Virtual Terminal?

I am trying to log into an ssh server by pulling the password directly out of the pass program without any GUI interaction. The normal workflow in the GUI (Gnome) is to do the following. Pull the ...
2
votes
1answer
38 views

How to safely transmit a password over SSH for a remote command to use

On the local server, I have a program that stores the password in the predefined environment variable (SPECIAL_PASSWORD). On the remote server I have a program that reads and uses a password from a ...
2
votes
3answers
364 views

Use config file for my shell script

I need to create a config file for my own script: here an example: script: #!/bin/bash source /home/myuser/test/config echo "Name=$nam" >&2 echo "Surname=$sur" >&2 Content of ...
3
votes
1answer
19 views

Bash prompt: using \[ and \] within PROMPT_COMMAND

I'm working on a bash prompt. I'm also trying to create the prompt intelligently, so that it will be easily readable and maintainable. That means not having one huge export PS1. Various sources ...
0
votes
0answers
29 views

awk search for string containing forward slash in variable [duplicate]

I'm searching for a string in a massive XML file. Snip: <sv:node sv:name="notfound"> <sv:property sv:name="jcr:primaryType" sv:type="Name"> ...
0
votes
1answer
49 views

Script to check if file exists and copy

Pretty new to shell script, Want to write script which checks if any file .300 extension exists on /exports/files on server 10.xx.xxx.xx .If *.300 exists, move file to /exports/files/arch and send an ...
3
votes
5answers
129 views

source multiple files and output one file

I have a file name "conf1" containing variables like: name='john' last='' custom='1000' and another file name conf2 like this: name='john' last='star' I want to merge between them to one file ...
0
votes
1answer
18 views

Update mysql database specific field with this bash script

I am using the following bash script to update an email address "currentemail@email.com" but the problem I have is that the field could be anything, not necessary "currentemail@email.com" I have tried ...
3
votes
3answers
2k views

Can I run Bash scripts in FreeBSD without modifying them?

Correct me if I'm wrong: "sh" script != "bash" script Linux script are written in Bash Bash script usually #!/bin/sh In GNU/Linux, /bin/sh is Bash In FreeBSD, /bin/sh is not bash, it's the true sh ...
5
votes
2answers
589 views

How to delete a directory automatically when an executable is killed

Quite often, we run an executable that needs to write / read some temporary files. We usually create a temporary directory, run the executable there, and delete the directory when the script is done. ...
0
votes
0answers
18 views

What is the bash path difference if asterisk is inside doublequotes or outside doublequotes? [duplicate]

Task is to copy all the files (*). I have this command failed (no path found): cp -r "somedir with space/*" /tmp But this works fine: cp -r "somedir with space/"* /tmp So, what's wrong with path ...
3
votes
2answers
262 views

How to find all paths not compatible with Windows?

On most Linux filesystems, NUL (\0) is the only invalid character in paths (and / is reserved as the path separator). Windows has a complicated set of rules for valid paths. Rather than fixing paths ...
0
votes
1answer
30 views

Run a query and Send out email

I created a script to monitor and have a query as below :- httpUrl="http://some.website.ashx" balExp=$(curl -v -X POST -d "UID=test&PWD=2222" $httpUrl) How do I sent email alert (my email ...
1
vote
2answers
12 views

Delete files that are not part of a bash array

Right now I backup the mysql databases using a cronjob everyday. Now that the server is getting full, I only want to keep one backup for every month, one backup from sunday every week and the last 7 ...
3
votes
3answers
69 views

How can I count the number of times a phrase appears in a file, and format it neatly?

I have a log file I am trying to pull data from. It is formatted like so, and lists when certain modules are checked in and out: 19:50:26 (license_manager) OUT: "certain_module" doej@server.domain ...
2
votes
1answer
37 views

move back to the end of bash history when using reverse search?

I keep fairly long bash history and sometimes when I search for something with bash reverse search function(Ctrl+r) I end up at the beginning of search history and I still did not find what I needed ...
0
votes
3answers
45 views

Throw away standard output and error

I have redircted my ouput using /dev/null in bash script but it is still throwing an error. Code is following ps -p $proc | fgrep $proc> /dev/null if [ $? -ne '0' ] ; then ...... fi below is ...
1
vote
0answers
39 views

Clear the terminal in “vi” mode? (equivalent of “ctrl+l” from “emacs” mode) [duplicate]

I am aware of Ctrl+L on bash terminal (using it on Ubuntu) which clears the screen by applying appropriate scrolling on bash terminal. After learning that the terminal is by default set to emacs mode ...
1
vote
5answers
40 views

Output to variable with an indirect command (eval)

What is wrong with this indirect command when run with eval ? #!/bin/bash OS=AIX host=myhost CMD_AIX="(o=\`host \"$host\" \`)" CMD=\$CMD_$OS echo $CMD eval echo $CMD eval "$CMD" Ouput: $ ...
2
votes
1answer
53 views

Can bash brace expansion be performed within quotes

In an attempt to dry up my bashrc, I tried changing this, CDPATH=".:~/Development:~/Development/resources:~" to this, CDPATH=".:~/Development{,/resources}:~" But I found the brace expansion ...
1
vote
1answer
28 views

Why does bash try to execute strings in a string substitution?

My script is supposed to take input from a pipe and replace newline characters with commas, using the bash's string substitution: #! /bin/bash read -d -r input echo $input $input=${input//\n/,} ...
2
votes
3answers
264 views

How to lock screen for a terminal session?

as we could use xflock4 command to lock the screen (ask for a password to continue) in an X session; I need a similar way to lock the tty1 session. Is there any? (logout is not working when I call in ...
11
votes
2answers
338 views

Unexpected Bash completion of ~ on OS X

I pressed ~TabTab on the bash command prompt and got an unexpected set of completions. First it looked like all the folks in the /Users directory, and a lot more. Then I thought it was doing the ...
33
votes
13answers
48k views

Is there a way to get the min, max, median, and average of a list of numbers in a single command?

I have a list of numbers in a file, one per line. How can I get the minimum, maximum, median and average values? I want to use the results in a bash script. Although my immediate situation is for ...
-1
votes
1answer
28 views

How can I execute and export in a single shellscript

I have two shell scripts. $ cat java_alternative_7 #!/bin/sh sudo update-java-alternatives -s java-7-oracle $ cat java_home_7 #!/bin/sh export JAVA_HOME=/usr/lib/jvm/java-7-oracle It's simple that ...
14
votes
3answers
7k views

How to check if pipe is empty

I have piped line in bash script and want to check if pipe has data, before feeding program Searching I found about test -t 0 but it doesn't work here. Always returns false. So how to be sure that ...
11
votes
6answers
3k views

Refer to a file under the same directory of a script found in $PATH

I have a bash script file, which is put under some directory added to $PATH so that I can call the script from any directory. There is another text file under the same directory as the script. I ...
4
votes
6answers
139 views

Append something to each list in a file

I have a file, lists.txt, that looks like this: // stuff at beginning of file var list1 = new Array(); i = 0; list1[i++] = 'a'; list1[i++] = 'b'; ... list1[i++] = 'z'; var list2 = new Array(); i = ...
0
votes
0answers
13 views

Changing from bash-4.3$ to [user@hostname currentfolder]# [duplicate]

I'm tring out different linux distros. I've settled on Fedora, but I'm a bit confused. On my other distros, my terminal would open up with a [user@hostname currentfolder]# before each prompt. Now I ...
1
vote
1answer
23 views

bash show-all-if-ambiguous turns on spontaneously

I am using tmux and bash. I find that, at seemingly random intervals, my running shells have show-all-if-ambiguous set to on. This is a significant annoyance to me, since many of my operations are in ...
1
vote
1answer
28 views

I am attempting to write a bash script to convert hex to base64

I am attempting to do the matasano cryptopals challenges in bash. The first step is here I found this stackexchange thread with a partial solution. printf 49276d2 | xxd -r -p | base64 which ...
1
vote
0answers
13 views

How can I change readline settings on keypress?

I checked docs for readline (in man bash), and I can't find a way to solve one problem: how to change readline setting (set ... on/off) on keypress? Keybindings seem to have form: key:function or ...
0
votes
3answers
85 views

Concat 1000 files within a directory [closed]

I know we can concat files by cat file [file] [[file] ...] > joined-file. I have directory which contains lots of files. I want to concat all of them. I want to concat 1000 files irrespective of ...
2
votes
4answers
101 views

Script to log temperature

I have been trying to write a BASH script to log my raspberry pi's temperature. My plan is to run it as a crontab every 15 mins or something. However I keep getting errors, I think it's something to ...
27
votes
4answers
15k views

Reading lines from a file with bash: for vs. while

I'm trying to read a text file and do something with each line, using a bash script. So, I have a list that looks like this: server1 server2 server3 server4 I thought I could loop over this using ...
1
vote
1answer
22 views

gzip files with cat and from pipe gives different results

Why does this give such output (both commands are supposed to do the same thing) and how can one make them give identical output? diff <(cat some_file | gzip -c - | base64) <(gzip -c some_file ...
3
votes
0answers
33 views

bash - ignore case but disallow autocomplete if ambiguous

Recently i face inconvenient when using bash auto complete with ignore case. Let's say i have this directories: [xiaobai@xiaobai test]$ l total 20K 3407873 drwx------. 60 xiaobai xiaobai 4.0K May 25 ...
4
votes
4answers
244 views

grep command not working in conditional statement

I've a bash script that's supposed to go over all the filenames and print them only those that contain a certain letter (let's say it's 'o'). What I've done: command=`ls -l` for file in $command do ...
-2
votes
1answer
35 views

Move folder from root of Hard Disk to Current Directory [on hold]

I'm trying to figure out how to move a folder that sits in the root of my disk (what do you call that, home?) to a subdirectory. I am not cd'd to the root (again not sure of the terminology). When I ...
8
votes
4answers
24k views

Change font in echo command

Is it possible to change the font attributes of the output of echo in either zsh or bash? What I would like is something akin to: echo -n "This is the font: normal " echo -n $font=italic "italic," ...
16
votes
1answer
528 views

Is it standard behaviour for cd to automatically choose when given an incomplete directory name?

I have three folders called ProjectA, ProjectB and ProjectC. When I tab-complete cd to cd Project and press Enter, it chooses ProjectC. I've found this is also the case with other similar cases; it ...
2
votes
1answer
2k views

Can I change uuid for network interface in ifcfg-eth* using uuidgen?

I'm creating a script which configuration the network interfaces. The script which generates /etc/udev/rules.d/70-persistent-net.rules and names interfaces to my preference. In CentOS 6.5, my ...
4
votes
3answers
246 views

How to use printf and %s when there are color codes?

I had these lines: if [[ $# -eq 0 ]]; then printf "$fail_color Error - Function: $function, Line: $line_number \n" printf "do_test: Third parameter missing - expected result\n" exit 1 fi This ...
3
votes
2answers
4k views

How can I run as another user?

This is the bash code that should be runned. So first it substitutes the user to openproject and than runs all the code su openproject -c "bash -l" cd ~/openproject git checkout Gemfile.lock git ...
21
votes
4answers
11k views

Can't use exclamation mark (!) in bash?

I'm trying to use the curl command to access a http url with a exclamation mark (!) in its path. e.g: curl -v "http://example.org/!287s87asdjh2/somepath/someresource" the console replies with bash: ...
5
votes
3answers
193 views

Easiest way to find missing quote in a bash a script?

I have a bash script which is currently 700+ lines long. After a particularly long round of editing, it now errors like so: ./run_me.sh: line 693: unexpected EOF while looking for matching `'' ...
0
votes
2answers
28 views

Log file processing [on hold]

I have a log file like this; I can get NOW=HOUR=date +'%H' I can get login time in hour with something like cat file | awk '{print $2}' | cut -d: -f1 Is there a way I can compare the login times ...
7
votes
2answers
4k views

opening multiple URLs from a text file as different tabs in Firefox/Chrome?

How I would go about opening multiple URLs from a text file as different tabs in Firefox/Chrome? My text file is just a list of URLs, one per line: http://www.url1.com http://www.url2.com ...