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

determining column number using string in awk

Suppose I have a pipe separated file like: |Sr|Fruits|Colors| |1 |apple |red| |2 |orange |orange |3 |grapes |purple| Here it is evident using awk that, $2 is Fruits and $3 is the colors column. ...
4
votes
3answers
95 views

How can I delete a file named “>”?

I was running a Python script that malfunctioned and used sudo to create a file named >. How can I get rid of this file? Of course, when I try sudo rm >, I get the error bash: syntax error ...
1
vote
3answers
43 views

find directories with specific patterns leads to Permission denied error and no result

I have this kind of shell script on Linux: #!/bin/sh echo -n "Please enter directory pattern: " read dirs find $dirs > /tmp/justbay.txt allDirs=$(find $dirs ! -readable -prune) echo $allDirs ...
0
votes
2answers
58 views

works as a command but not as a shell script. Why?

$ grep "apple" fruits.txt apple $ if [ $? == 0 ] ; then echo "A"; else echo "B"; fi A When I execute the above commands it works fine but when I run these commands as a shell script it throws error ...
5
votes
3answers
141 views

Can you execute a Bash function with the `at` command?

I want to execute a Bash function at a scheduled time. I think the right tool for this is the at command. However, it doesn't seem to be working. function stupid () { date } export -f stupid ...
1
vote
3answers
32 views

rsync adding extra directory to command

I'm scripting an rsync command, and currently I am trying to do something like... rsync -av -e ssh $DATASTORE/usr/local/somepath $DESTDIR/usr/local/someotherpath/ if I echo $DATASTORE it shows ...
3
votes
4answers
44 views

find on a set of dirs that may not exist

I need to invoke find on a set of "starting points" which is generated, but some of paths may not be valid: paths() { # # mock version of the generator # echo /bin echo kjsdfhk ...
3
votes
2answers
50 views

What is the difference if I start bash with “/bin/bash” or “/usr/bin/env bash”? [duplicate]

In shell scripts one specifies language interpreter on shebang(#!) line. As far as I know, it is recommended to use #!/usr/bin/env bash because env is always located in /usr/bin directory while ...
0
votes
0answers
33 views

Kill the process and restart server when memory is exceeded - bash and cron

I have a site on webfaction, using django and python. However, I have problem with memory. The problem arises, because I use external library, that can run forever (consuming much time and memory). ...
0
votes
0answers
38 views

How to turn Diff command into bash script with prompt

I have a list that i've copy and i want to paste it to the shell to give me just the repeated lines. 1 1 3 2 As i read about bash commands i've maded this: cat > /tmp/sortme ...
0
votes
0answers
21 views

How to grouped the following variable and command and read 1 by 1

I've following array and variable : httpurl="http://www.nnin.com" firstquery=$(curl -s -X POST -d "UID=user1&PWD=1111" $httpurl) name="firstcust" ip="105.105.0.1" httpurl="http://www.mmim.com" ...
0
votes
3answers
68 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 ...
2
votes
1answer
51 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
1answer
39 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
31 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"> ...
4
votes
3answers
9 views

Inject lines to bash history

By default bash loads lines from ~/.bash_history to history. Is it possible to add custom file to be also loaded? I want to inject file containing commands I frequently use and access them it via ...
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
3answers
118 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.xx.xx. If *.300 exists, move file to /exports/files/arch and send an ...
0
votes
0answers
19 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
136 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
23 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
71 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
30 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
17 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
15 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
46 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
55 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
354 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
30 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
23 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
556 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
36 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
141 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
247 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
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 ...
0
votes
2answers
28 views

Log file processing [closed]

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
251 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
33 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
195 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
64 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 [closed]

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
80 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 ...