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
12 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 ...
1
vote
0answers
16 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 ...
0
votes
0answers
25 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
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 ...
0
votes
1answer
43 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 ...
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
5answers
128 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 ...
3
votes
1answer
13 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 ...
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 ...
1
vote
1answer
27 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
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 ...
0
votes
2answers
5 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
2answers
10 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 ...
0
votes
3answers
44 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 ...
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 ...
11
votes
2answers
337 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 ...
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
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 ...
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 ...
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 ...
16
votes
1answer
520 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
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 ...
4
votes
6answers
136 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 = ...
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
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 ...
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
0answers
32 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 ...
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 ...
4
votes
4answers
241 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 ...
0
votes
1answer
30 views

cant run dd command on android device

The main objective is to send a splited file to an android and join it back up with a .sh script, the file is splited to 5MB parts but its total size is unknown (trying to make an universal script), ...
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 `'' ...
4
votes
1answer
63 views

How does Bash auto completion work?

I can understand that bash auto completion works for standard utilities. But how does it do auto completion for custom programs like Oracle SQL loader? In the following command if you Tab after ...
4
votes
4answers
142 views

Move files by date into different directory using CLI

I have a large number of pictures from an old hard drive that I'm trying to organize. If I run ls -l, I notice all of these files have a creation date of 2012 or before. Ideally, I'd like to move ...
0
votes
0answers
17 views

What are potential problems for installation scripts modifying .bashrc [on hold]

Some software packages advices you to make an alias for a certain program,... in other words modifying the ~/.bashrc, ~/.profile files. Little of these packages have an installation script that make ...
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
79 views

Extract two values from the output of a command

I'm using the following command in a script to get synthetic wifi info: echo "$( iw dev wlp1s0 link | grep '^\s*SSID:\s' | sed -r 's/^\s*SSID:\s//' ) $( iw dev wlp1s0 link | grep ...
2
votes
3answers
47 views

How can I prepend and append to each member of an array?

I have an array: CATEGORIES=(one two three four) I can prepend to each array member using parameter expansion: echo ${CATEGORIES[@]/#/foo } I can append to each array member the same way: echo ...
0
votes
1answer
39 views

Test variable in a bash case statement

What I want is simply to do something if the first variable of the script is empty, in a case statement. Unfortunately I spent yet a certain amount of time searching for the solution but didn't find ...
0
votes
2answers
29 views

Timeout function return value

I'm using the timeout function on debian to wait 5 seconds for my script. Works great but the problem I have is that I need a return value. Like 1 for timeout and 0 for no timeout How am I going to ...
3
votes
0answers
42 views

Bash Script — ffmpeg not being invoked as expected

I'm working on a bash script to convert my music library to ogg* but executing the right command is somehow eluding me. This is the line that should accomplish it: ffmpeg -i "${file}" -f flac pipe:1 ...
0
votes
0answers
16 views

Why “killproc” command is unable to terminate a script(whiled loop with inter sleep)? [closed]

How to terminate a whiled loop script using "killproc" without using script's pid?
0
votes
3answers
51 views

bash: Assigning the first line of a variable to a variable

I have a multiline variable, and I only want the first line in that variable. The following script demonstrates the issue: #!/bin/bash STRINGTEST="Onlygetthefirstline butnotthesecond orthethird" ...
0
votes
0answers
18 views

How can I copy the previous argument for the *current* command? [duplicate]

I can use Alt+. or !$ to get the last argument passed to the previous command, however, is it possible to get the last argument passed to the current command? For example, something that I do ...
0
votes
1answer
20 views

Help killing off Process for Mem Leak

I am currently building an Android LP kernel, and have some pretty sweet tweaks already running and built into it. I know there are numerous LP memory leaks (i've already got the bootanimation one ...
0
votes
1answer
43 views

SSH: remote variable

I want to run a complex script via ssh #!/bin/sh ARRAY1=( server1s server123 server12 server14 server13 ) for i in ${ARRAY1[@]};do ssh $i " case \$HOSTNAME in server1.domain.com) echo try1 ...
-1
votes
1answer
31 views

Webpage content - search for pattern & save to file

I have a web page, say https://test.salesforce.com. I would like to search for a pattern, e.g. "src" at the beginning of a line in the entire webpage content. If the pattern is found, I need to ...
1
vote
1answer
13 views

getting case insensitive completions with compgen in bash

I'm trying to get my command (devmode2) auto-completing with bash working with compgen -W, my bashrc has: _devmode2() { COMPREPLY=() local sonames=$(devmode2 --auto --current "${COMP_CWORD}" ...
0
votes
2answers
59 views

export PATH permanently [duplicate]

I have exported the PATH but once I switch to a different terminal or reboot Debian, $PATH is reset. Here are the steps I take: ~$ vim scripts.sh #!/bin/bash echo "Hello" I save it as mybash.sh ...
0
votes
2answers
34 views

Generate a list of installed PHP extensions

My goal is to write an as simple as possible (but not more simple) that generates a list of currently installed PHP extensions (*.so files) that the user can simply copy/paste into their php.ini. It ...