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

How to create cross-platform keyboard bind commands?

I'd like to have the same keyboard shortcuts in all the terminals I use. Since they don't have the same *nix on them, and since terminals can be very different, I'm looking for a reasonably portable ...
3
votes
2answers
495 views

How to write an abort-on-error script without adding `|| exit $?` to every line?

I'm writing a bash script that should exit the error code of the last failed command and not continue execution. This can be achieved by adding a || exit $? everywhere, but is there an easier way, ...
3
votes
1answer
344 views

Display the command being executing currently

I don't recall to have explicitly placed anything in my .bashrc file recently, but from yesterday I am able to see the command being displayed at the prompt before getting executed. I don't know how ...
7
votes
2answers
314 views

Need help on this bash auto completion script

I'm trying to setup autocompletion for a command, which takes only one parameter, a folder name, In /secure/kernel_builds/, I have the three following subfolder: 3.5.6/ 3.6.2/ source/ Now I want ...
15
votes
2answers
17k views

Bash: How to read one line at a time from output of a command?

I am trying to read the output of a command in bash using a while loop. while read -r line do echo "$line" done <<< $(find . -type f) The output I got ranveer@ranveer:~/tmp$ bash ...
4
votes
3answers
2k views

Bash shells with different environment variables

I want to somehow enter a different bash shell with some altered environment variables. For example, if I run script bfin.sh and it contains something like export PATH=/home/me/bfin2012:$PATH I ...
5
votes
3answers
2k views

What's the right way to sort a associated array in bash or zsh?

I'm wondering how should I sort the associated array in bash? I tried the manual, but seems nothing related to sort. The current solution is echo everything out, and use external program i.e key ...
4
votes
2answers
346 views

Why am I observing different behaviour of echo?

I am a bash beginner and observed the below behavior of echo #!/bin/bash x=" hello" echo $x echo "$x" Now when I run the above code I get ronnie@ronnie:~$ bash test.sh hello hello ...
7
votes
1answer
13k views

bash - how to uppercase the command line argument?

I searched SO and found that to uppercase a string following would work str="Some string" echo ${str^^} But I tried to do a similar thing on a command-line argument, which gave me the following ...
1
vote
2answers
668 views

ps aux |grep 'asdf' grep: asdf: No such file or directory

For some reason a while back, the behavior of my command line changed, and I don't know why. Using OSX, now Mountain Lion(although this behavior was present before the switch). Using standard ...
0
votes
2answers
185 views

sqlite fts quoting problem

I can do this in sqlite tool: sqlite> select caption from notes_fts where notes_fts MATCH '"perl install"'; but cannot from the Linux shell i.e., this fails: user@host:~$ sqlite3 sqldb ...
0
votes
1answer
245 views

How to effectively use bash scripting (different cost reductive ways and good habits)? [closed]

This is one of the most perennially important questions. How to effectively script ? What are the bad ways and what are the good ways ? I know of some, which i will point out here. If anybody does ...
0
votes
1answer
2k views

bash script to gzip files

I have to make a bash script that do a gzip of a file if is older than 60 days, and move it in a subdir which name is the beginning of the filename. Here an example of the files I have to work with: ...
4
votes
2answers
331 views

Redirect stderr of the double-parentheses construct

I'd like to be able to redirect the stderr of a double-parentheses construct. For example: a=$(($var/$var2)) would output some error messages if $var2 = 0, I do not want the user to see this. I ...
5
votes
1answer
382 views

How to merge multiple WebDAV accounts for backup?

I use davfs, aufs, rsync: sudo mount -t davfs -o uid=wd,gid=wd,dir_mode=777,rw https://wd1.wd.wd/ /mnt/webdav1 sudo mount -t davfs -o uid=wd,gid=wd,dir_mode=777,rw https://wd1.wd.wd/ /mnt/webdav2 ...
4
votes
4answers
8k views

Need a loop to sleep for a fraction of second

On my machine I need to execute a cycle that iterates 1 simple command that must have a delay expressed in fractions of second. Let's say that I need: to save a file with an increasing enumaration ...
4
votes
2answers
369 views

Function caller positional parameters

I need to read and write the positional parameters $@ of a function's caller. The Bash man page says that: A shell function is an object that is called like a simple command and executes a ...
5
votes
2answers
1k views

Requesting user input while reading file line by line

For class I need to write a Bash script that will take the output from ispell and when I try and request user input inside the while loop it just saves the next line of the file as the user input. ...
19
votes
3answers
10k views

How to combine 2 -name conditions in find?

I would like to search for files that would not match 2 -name conditions. I can do it like so : find /media/d/ -type f -size +50M ! -name "*deb" ! -name "*vmdk" and this will yield proper result ...
7
votes
2answers
460 views

When is it useful to use “grep — SOMEPATTERN”?

So under Linux/AIX where ever.., when is it useful to use: grep -- SOMEPATTERN the Question is the "--" part. When is it usefull to use?
3
votes
4answers
4k views

How to detect dos format files in git bash

Git Bash is a nice bash shell you get in Windows as part of the installation of Git. It comes with other typical unix tools bundled inside, such as grep, sed, awk, perl. It doesn't have the file ...
4
votes
2answers
11k views

How can I detect that no options were passed with getopts?

I have this code - #getoptDemo.sh usage() { echo "usage: <command> options:<w|l|h>" } while getopts wlh: option do case $option in (w) name='1';; ...
5
votes
3answers
2k views

Test command in unix doesn't print an output

When I type this in the terminal test 4 -lt 6 I don't get any output. Why not? I need that 0 or 1
11
votes
3answers
9k views

What is the difference between grep -e and grep -E option?

I am trying to understand the difference between grep -e and grep -E. Now from grep manpage I got: -E, --extended-regexp Interpret PATTERN as an extended regular expression (see below). ...
1
vote
4answers
209 views

Syntax error in a bash script that calls find

Where is the error in this script please: #!/bin/bash rep="git" files=`find' ${rep} '-type f` for f in ${files} do echo $f done When i run find git -type f alone in the shell, it works!
3
votes
4answers
169 views

Editing output of command as a new command

I have a script that outputs a string that I would like to edit and then run as a command. For example, I am using cat ... | xsel -p And then I want to edit the output of `xsel -op´ and run the ...
1
vote
5answers
975 views

Run a command on all the files in a directory tree and put the output into a variable

I want to run this bash command : #!/bin/bash rep="*" for f in `ls -R`$rep; do d='git log '$f'| wc -l' c=$d echo $c done how to excute a command git log myFile | wc -l from bash ? ps : this ...
1
vote
1answer
592 views

How to create script that toggles one value in synclient?

I use synclient touchpadoff=1 to disable touchpad and synclient touchpadoff=0 to enable touchpad. $synclient | grep TouchpadOff TouchpadOff = 1 I'd like to create script that will ...
1
vote
2answers
453 views

List info about files/directories with spaces

I am trying to use ls to get information about files and directories. My current command fails to properly get the name whenever a file/directory has a space. I am using this to list all ...
7
votes
3answers
721 views

shell scripts are still working without #!(sha-bang line)

I am new to shell scripts and many books have written that use #!(sha-bang) line in starting of the script to invoke the interpreter .And this will invoke a new shell for script and do the ...
9
votes
1answer
1k views

Re-run multiple history commands

Imagine you've just run a dozen commands. Say... $ cd foo/ # history cmd #10000 (my history is very long) $ ... more commands ... $ cd ../ # history cmd #10012 I know I can re-run them ...
2
votes
4answers
5k views

Get full path from within Bash script

I have a bash script that works with relative paths. It needs to have a working directory that is equal to the directory the script is stored in. This works fine as long as I start it from the prompt, ...
3
votes
1answer
413 views

How to set up `screen` to modify the window title and xterm-window title?

I'd like to have my current $PS1 prompt (\u@\h:\w$(__git_ps1 "(%s)")\$ plus some coloring) to be also used as screen's window title (in the hardline) and as the xterm window title. How can this be ...
3
votes
2answers
406 views

I specifically want to delete my grep output string from the text file [duplicate]

Possible Duplicate: I specifically want to delete my grep output string from the text file I'm a little bit new with Linux and I have a problem. I have a text file called file_a.txt My ...
1
vote
3answers
131 views

Restructuring directories into a hierarchy

I have the following type of folder structure containing thousands of folders. The folder names are as such with different names etc .test .test.subfolder .test.subfolder.subsubfolder .folder ...
5
votes
5answers
4k views

How do I perform an action on all files with a specific extension in subfolders in an elegant way?

My current best bet is: for i in $(find . -name *.jpg); do echo $i; done Problem: does not handle spaces in filenames. Note: I would also love a graphical way of doing this, such as the "tree" ...
3
votes
3answers
363 views

Is there an equivalent of calling the built-in python function help('topics') but in bash?

I would like to explore man pages in bash using something similar to the python help('topics') function. Does this exist in bash? I know the bash equivalent of python's help('modules') would look ...
1
vote
1answer
339 views

Calculate difference between two non-linear data sets [closed]

I would like to calculate the difference between two data sets at any given moment in time. The problem is that the "timestamps" at which both data sets were taken differ. For example consider these ...
4
votes
3answers
3k views

Using OR patterns in shell wildcards

Contents of my dir are $ ls -lrt total 0 -rw-r--r-- 1 user1 admin 19 Oct 8 12:31 night.txt -rw-r--r-- 1 user1 admin 19 Oct 8 12:31 noon.txt -rw-r--r-- 1 user1 admin 38 Oct 8 12:31 day.txt I ...
4
votes
2answers
630 views

List files created on Sundays

How do I list/find all the files created on Sundays or Mondays? How do I use the date parameter to display them? Something like : ls -f date + %a or find -type f | date +%A or find -type f ...
7
votes
1answer
323 views

What's the point of using “x$START_DAEMON” = “xyes” here? (the heading x)

This was part of fetchmail deamon script, if [ ! "x$START_DAEMON" = "xyes" -a ! "$1" = "status" ]; then What's the point of using x$START_DAEMON = "xyes", why not just use $START_DAEMON = "yes" ?
1
vote
1answer
443 views

How to make FreeBSD variant of cal start weeks on mondays?

Can week start day be changed in cal output? Is it hardcoded? Notice: not the ncal.
1
vote
3answers
813 views

what is wrong with my simple choice menu script?

This is a simple script which should let me go to to directory of my choice, but its not working as intended. #!/bin/bash showMenu() { echo "1) ocaml" echo "2) python" echo "3) csharp" ...
4
votes
4answers
6k views

Bash Auto-Completion feature for SSHing into Different Hosts

I have big list of servers which I normally ssh to all the time. Is there any way using bash or zsh so that I can keep the list of hostname and bash auto-completion goes through the file and gives me ...
5
votes
2answers
630 views

Use a script parameter in awk

Here is my script (to find the files that contain a specified pattern) : find . -type f -exec awk -v vawk="$1" '/'"$vawk"'/ {c++} c>0 {print ARGV[1] ; exit 0 } END { if (! c) {exit 1}}' \{\} \; ...
2
votes
1answer
593 views

Fix symbolic links after version change

Say I have a symbolic link to a file, which has its version in its name. (The file is actually a jar file) Now say, that the version changes, i.e the old file I linked to is deleted and a new one is ...
1
vote
1answer
1k views

Is it possible to use a parameter within an alias command [duplicate]

Possible Duplicate: How to pass parameters to an alias? As answered in Can less retain colored output? I want to use git diff --color=always filename | less -r to get a colored output of my ...
11
votes
1answer
2k views

ls everything that is _not_ a symlink

Does ls have a way to show negated conditions like "all files which are not a symlink"? I use the latter a lot in a project directory but other negations would be useful as well. For now, my research ...
1
vote
4answers
2k views

Bash script for loop with find and many directories

I'm writing a bash script to do some work on a directory that contains many (100,000+) sub-directories. Is there a predefined limit to how many arguments you can pass to a for loop such as the ...
13
votes
2answers
10k views

/dev/tcp listen instead of nc listen

With a netcat listener like: nc -l <port> < ~/.bashrc I can grab my .bashrc on a new machine (doesn't have nc or LDAP) with: cat < /dev/tcp/<ip>/<port> > ~/.bashrc My ...