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

7
votes
2answers
462 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
10k 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
214 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
171 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
1k 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
623 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
463 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
736 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 ...
10
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
422 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
420 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
133 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
380 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
4k 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
659 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
342 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
461 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
825 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
641 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
600 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
11k 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 ...
2
votes
1answer
262 views

Is there a way to control the speed at which Curl reports progress?

I'm using Curl in Cygwin to automate a daily download. I want to keep progress in a log but Curl is just a little too noisy for my taste. I tried man curl and Google, but didn't find anything. Can I ...
12
votes
3answers
5k views

Recursive glob?

I'd like to write something like this: $ ls **.py in order to get all .py filenames, recursively walking a directory hierarchy. Even if there are .py files to find, the shell (bash) gives this ...
2
votes
1answer
966 views

Bash overwrites the first line, PS1 bash prompt

I have played around with PS1 and PROMPT_COMMAND in bash to create a zsh-style right side prompt. I have a solution who almost works. The problem is that if I write a long line of input, the second ...
1
vote
1answer
1k views

How to manage getops argument assignation

This is my first question. I'm trying to make a small script with options and I'm using getopts to do it. The weird thing is: The argument don't get assigned to the variable or it always enter the ...
3
votes
3answers
3k views

Conditional crontab command in bash script

How do I invoke a crontab command so that I can schedule to run a script with a 20 minute delay based on some condition? Edit: What if I wanted a command that schedules a script to be executed only ...
5
votes
1answer
509 views

How does sh -e interact with &?

I'm using sh (dash) on Ubuntu (lucid) and the manpage has this to say about -e: -e errexit If not interactive, exit immediately if any untested command fails. ...
0
votes
1answer
1k views

seq - invalid floating point argument error

I have a file with many numbers, with each number on one line. My goal is to find the numbers that are missing. I'm trying to generate the sequence of all the numbers with seq start=$(head -1 ...
5
votes
2answers
1k views

How to put the specific files from a directory in an array in bash?

Suppose I have a directory under which there are 3 files named: file1.txt,file2.txt and file3.txt. Now how can I fill an array with those file names(I just know that all the files have certain ...
1
vote
3answers
5k views

bash merge 2 lists removing duplicated

I have an embedded linux system using Busybox (OpenWRT) - so commands are limited. I have two files that look like: first file aaaaaa bbbbbb cccccc mmmmmm nnnnnn second file mmmmmm nnnnnn ...
10
votes
2answers
2k views

Interactively deleting files from a list

I'd like to remove a list of files and be asked for confirmation. The list is in the list.txt file. Why the following command doesn't work properly? while read i; do rm -i $i; done < list.txt ...
2
votes
2answers
1k views

BASH: Grouping files by name

I have over one million files. And I have to proceed over them. My files' directory hierarchies just like below source=/opt/output/renamed/ target=/opt/output/combine send=/opt/output/send/combined ...
5
votes
1answer
612 views

Symbolic links with ls, mv: forcing the functions to utilize “logical” addresses (remembering the original path)

It seems that for many basic functions operating on symbolic links, the physical path is used by default. However, cd works fine. When moving into a symbolic link, cd remembers where I came from so it ...
5
votes
2answers
3k views

Reading character by character with bash read

I've been trying to use bash to read a file character by character. After much trial and error, I have discovered that this works: exec 4<file.txt declare -i n while read -r ch <&4; ...
8
votes
1answer
2k views

Bash history with timestamps

I would like to keep timestamps on the commands logged in my Bash $HISTFILE, is it possible? I did not manage to set it up using man bash as an information source. My other options are as follows: ...
6
votes
4answers
2k views

How to get the relative paths with ls?

I'd like to do something like this to move the last two downloaded files: mv ` ls -rt ~/Downloads/ | tail -2 ` . Unfortunately, ls only gives the filenames. How can I adapt the code above? (Before ...
1
vote
3answers
3k views

How to know if a file has been written completely?

I have shell script which waits for some files to arrive from remote machine, when it arrives, it cats them to a new file. For that I am using a while loop,like following: while true do if [ ...
2
votes
1answer
501 views

Download file linked in MySQL DB, extract text and insert into db with bash script?

I want to download a file (only download if the url ends with a certain string), which URL is in a MySQL database, extract the text and write the text to the database, by replacing the url. And this ...
1
vote
2answers
727 views

Auto-expansion problem with array elements containing an '*' (asterisk)

I'm trying to write me a find script that should later be able to read a list of directories to be excluded from an external file. Whilst I can accomplish that part myself, it's the annoying array ...
2
votes
3answers
860 views

Is there a way to get *actual* (uninterpreted) shell arguments in a function or script?

I have a function posix that I use in the Git bash shell on Windows to transform DOS-style paths to normal Unix-style paths. Since DOS-style paths use a backslash as separator, I have to quote the ...