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
0answers
11 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
3answers
23 views

Specific column level substitution

If I have a file with columnar entries, is it possible to substitute specific entries from a specific columns only and save changes to the same file?? Example a file abc.txt: SR|FRUITS|COLOR| ...
0
votes
3answers
37 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
28 views

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

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 ...
10
votes
2answers
315 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
26 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
0answers
28 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
10 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 ...
14
votes
1answer
495 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
34 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
122 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
3answers
27 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
97 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
242 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
30 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
231 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
28 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
182 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
135 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
16 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
82 views

Concat 1000 files within a directory [on hold]

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
78 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
46 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
36 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
27 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
39 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)? [on hold]

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
41 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
33 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 ...
0
votes
2answers
24 views

Get or filter duplicated lines by column

I have a file with three columns and I would like to get duplicated lines by third column, for example: AAA = 342 BLABLABLA = 2 BBBx2 = 23 1+1 = 2 KOKOKO= 5 2x1 = 2 The output sould ...
1
vote
1answer
22 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 ...
2
votes
1answer
43 views

How do I properly escape this long su + sed command?

#!/bin/bash wineuser=tom su $wineuser -c "sed -i '$ialias ptgui "wine ~/.wine/drive_c/Program\ Files/PTGui/PTGui.exe\"' /usr/people/$wineuser/config/cshrc.csh" The acutal line inserted to tom's ...
1
vote
0answers
39 views

Shell Script to change user shell

I am writing a script that would be invoked to change user shell. The basic requirement is that once user gets authenticated (e.g: thorough some web application) the script would be invoked to set the ...
7
votes
3answers
264 views

Does while spawn a subshell in bash? [duplicate]

Can someone explain why this script doesn't produce the output I was expecting? #!/bin/bash # var=0 ls -1 /tmp| while read file do echo $file var=1 done echo "var is $var" I get a ...
2
votes
3answers
54 views

Bash | port killing loop fails

I am trying to create a bash function which should kill all processes using some ports specified in port_array. The kill-port function works if I call it myself with a port e.g. with kill-port "80";. ...
1
vote
0answers
27 views

Inherit IO redirections from a script to another

When I redirect the output of a script within a script, I expect the redirection to be applied to the called script as well as the program called within it. A: ./B 2>> error.log B: ...
2
votes
3answers
145 views

Add extension for multiple files, based on their types

I know that there are many questions about adding extension to a multiple files. But none of them could get my job done. I have a huge list of images without extension, most of them are png, but ...
3
votes
4answers
96 views

Run multiple commands and kill them as one in bash

I want to run multiple commands (processes) on a single shell. All of them have own continuous output and don't stop. Running them in the background breaks Ctrl-C. I would like to run them as a single ...
0
votes
1answer
20 views

How do I run the query 1 by 1 and return only exit code in bash script? [closed]

I've created a below script :- query1=$(command1) query2=$(command2) query3=$(command3) if [ $? -eq 0] then echo "Success" exit 0 else echo "Failed" exit fi the problem is when I ...
0
votes
0answers
37 views

Output of wc | awk is different in shell script than from cli

When issued via command line, this returns "2": pgrep someprocess | wc | awk '{print $1}' When run in a script like this, it returns "4" #!/bin/bash SOME_PROCESS=`pgrep someprocess | wc | awk ...