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
3answers
10k views

bash string to int

Here is what I tried doing: #!/bin/sh res=`df | awk 'FNR == 2 { print $5 }'` res2=$((res+0)) Here is my error: -bash: 53%: syntax error: operand expected (error token is "%") I Googled ...
14
votes
3answers
43k views

linux + add X days to date and get new virtual date

I have Linux ( RH 5.3) machine I need to add/calculate 10 days plus date so then I will get new date (expiration date)) for example # date Sun Sep 11 07:59:16 IST 2012 So I need to get ...
9
votes
2answers
10k views

Global bash_profile

I realize there are /etc/profile and /etc/bashrc files for setting global environment variables and maybe I'm just misunderstanding their purposes, but... Is there a global bash_profile file? I'm ...
19
votes
5answers
6k views

How can I create an alias for a git [action] command (which includes spaces)?

Most of my my aliases are of this form: alias p='pwd' I want to alias git commit so that it does git commit -v But trying to create an alias with a space gives an error: $ alias 'git commit'='git ...
5
votes
4answers
647 views

How to shift filename numbers without collisions?

Consider this list of files: $ touch index-{1,2,3,4,5,6,7,8,9}.txt If I want to shift them down so they start at zero, it's relatively easy: $ rename --verbose 's/^index-([1-9])\.txt$/$1/; ...
2
votes
3answers
543 views

Adding breaks between every two words in bash

My Query is: QUERY="SELECT 'Your Name:', FullName, 'Your Phone:', Phone, 'Email:', Email FROM Table1 JOIN WHERE EmpID=001;" The output I get is Your Name: Samanta Your Phone: 111-111-1111 Email: ...
7
votes
2answers
3k views

Semicolon in conditional structures

Why put semicolons in one and not in another? The result is the same Code one if [ "a" == "a" ] then echo "true" fi Code two if [ "a" == "a" ]; then echo "true"; fi Semicolons in the second ...
0
votes
0answers
68 views

/long/path/to/{multiple, files} syntax? [duplicate]

Possible Duplicate: Quick way to include a directory path when calling mv? Is there any way in bash to type a path once, and then reference several files at once? Here's what I do now: ...
0
votes
0answers
40 views

How do I decide whether to make a command a shell script or an alias? [duplicate]

Possible Duplicate: In Bash, when to alias, when to script, and when to write a function? If I want to make a command like gsb that will expand to something like git show-branch -a | more ...
13
votes
4answers
4k views

How can I remove duplicates in my .bash_history, preserving order?

I really enjoying using control+r to recursively search my command history. I've found a few good options I like to use with it: # ignore duplicate commands, ignore commands starting with a space ...
3
votes
5answers
14k views

Bash iterate over a list of strings

I have this bash script: for opt in string1 string2 string3 ... string99 do somestuff It works, but I would like to replace the explicit listing of my strings with a file which actually contains ...
12
votes
3answers
31k views

sudo over ssh: no tty present and no askpass program specified

I keep getting this error and have tried several ways discussed online to fix this and none are working for me. I have setup SSH keys so when I run 'ssh newton@host.com' it automatically logs me in, I ...
3
votes
2answers
688 views

List of top level folders with contents no younger than 30 days

I have an automated system for creating FTP accounts (vsftpd with jailed virtual users) that works well, but I still rely on manual cleanup of stale accounts. My definition of a stale account is one ...
9
votes
5answers
5k views

How to make sure only one instance of a bash script runs?

A solution that does not require additional tools would be prefered.
0
votes
1answer
408 views

Unexpected token on bash file backtrack5 r2

When I log in, appears the following error: -bash: /etc/profile: line 1: syntax error near unexpected token (' Inside the file there is the next code: n# /etc/profile: system-wide .profile file for ...
16
votes
6answers
36k views

How to stop the loop bash script in terminal?

For example, #!/bin/bash while : do sl done How to terminate this bash script?
1
vote
2answers
163 views

run bash in script

I want to creat a script to run an another script with a several parameter exp=([1]=bloc [2]=ins [3]=rep [4]=op) for j in ${!exp[*]} do arr=([1]=mem [2]=gen [3]=usr) for i in ${!arr[*]} ...
13
votes
3answers
14k views

Understanding backtick (`)

I am trying out the command $ b=5; echo `$b`; -bash: 5: command not found but it does not print 5 as it is supposed to. What am I missing here? What does ` (backquote/backtick) mean in bash? seems ...
2
votes
1answer
239 views

A short way to call my bash script instead of use Source command

My script use and modifies a shell variable. I need to always use: source myscript Is there a shorter way to call this script and have it modify the current shell's environment? It can be ...
1
vote
0answers
37 views

Redirect hard return to other terminal [duplicate]

Possible Duplicate: Construct a command by putting a string into a tty Suppose I've run a command in a terminal ( /dev/pts/1 ) and it starts to ask me for input ( "press y to confirm" ) and ...
9
votes
5answers
333 views

How to count rows ordered by the first field in bash

Here is a snippet from the INPUT: ... #################### Bala Bela;XXXXXX12345;XXXXXX12345678;A SERVER345Z3.DOMAIN.com0 SERVER346Z3.DOMAIN.com0 SERVER347Z3.DOMAIN.com0 SERVER348Z3.DOMAIN.com0 ...
28
votes
3answers
15k views

What does it mean to have a $“dollarsign-prefixed string” in a script?

I just saw this in an init script: echo $"Stopping Apache" What is that dollar-sign for? My research so far: I found this in the bash manual: extquote If set, $'string' and ...
2
votes
1answer
112 views

Why is return is ignored during output in bash?

When I start a program that runs for a bit, say make, I could just type the next command in bash even before I got a prompt back and when the first command finished, the second one was executed as if ...
1
vote
3answers
8k views

Logical AND in a bash script

I have an if in my bash script that has to check if EITHER of the 2 files exists, if they don't exist it should echo match. Code I have: if [[ ! -f /etc/benchmarking/code ]] && [[ ! -f ...
4
votes
3answers
3k views

How do I use tee to redirect to grep

I don't have much experience of using tee, so I hope this is not very basic. After viewing one of the answers to this question I came across a strange beheviour with tee. In order for me to output ...
65
votes
12answers
26k views

How to grep a specific line _and_ the first line of a file?

Assuming a simple grep such as: $ psa aux | grep someApp 1000 11634 51.2 0.1 32824 9112 pts/1 SN+ 13:24 7:49 someApp This provides much information, but as the first line of the ps ...
4
votes
6answers
451 views

What is the easiest way to check if column A and B values goes both ways with AWK? [closed]

What is the easiest way to check if column A and B values goes both ways? Output to check: Mike John John Mike Pamela Barbara Barbara Pamela Mike Paul Roger Paul Desired output Mike <-> ...
3
votes
2answers
400 views

Am I using bash after this ordeal?

On Mountain Lion, host Coguaro, I login as user coconutpowder using bash: Coguaro:~ coconutpowder$ echo $0 -bash I need to run a command with elevated privileges so I try to su switch to root but ...
4
votes
3answers
4k views

Split command output by linebreak?

I have a command returning multiple lines. For further processing I need to process each single line of those lines. My current code works by modifying the IFS (Internal Field Separator): ...
3
votes
1answer
1k views

umask changes to 0002 after cd

I've noticed an odd behavior on my Ubuntu 12.04 LTS system. This is my first experience with Ubuntu; previously I used Fedora and never had this problem. I have set my umask in .bashrc to 0027. But ...
3
votes
2answers
622 views

Searching command history

I search the terminal command history by pressing Ctrlr but what if: This is an old command This is an | less -S older command I press Ctrlr and then I type "this is an" and the old command commes ...
5
votes
2answers
3k views

Fast elimination of duplicate lines across multiple files

I have a huge amount of data in which each (data-)line should be unique. There are a lot of files in one folder in which this is already true. It is about 15GB splitted into roughly 170 files with ...
19
votes
9answers
4k views

Bash commands inside vi

Is it possible to type a bash command inside vi and get the stdout? I find it often tedious to close and reopen vi just because I want to look something up in the shell.
2
votes
2answers
11k views

Combining multiple commands into a single line

I had a directory named myname which was archived in myname.tar. Now I want to take myname.tar, unarchive it, and delete all the files in the myname directory (after unarchiving). Here are my ...
2
votes
1answer
162 views

How to put “glue” CWD (etc.) to part of the screen instead of putting into PS1?

I suspect there’s some terminology for this question that I’m not aware of. It’s hard to check if a question has already been answered if one doesn’t know the proper vocabulary. So, sorry if this is ...
3
votes
5answers
2k views

Need to grep file with specific letter and move to another folder linux

I need to select files which contain "Error" or "traffic" in their names, e.g. abc_ERRor.csv raError.csv bsn_Error.csv bbbctraffic.csv ccc_traffic.csv ... and move them into corresponding ...
9
votes
2answers
889 views

Saving bash history from multiple Konsole not working correctly

I use multiple Konsole terminals. And I want all the commands I type in every terminal to be saved in command history, so that next konsole i open will have all of them. To prevent each terminal from ...
7
votes
1answer
29k views

In a bash script, using the conditional “or” in an “if” statement

This question is a sequel of sorts to my earlier question. The users on this site kindly helped me determine how to write a bash for loop that iterates over string values. For example, suppose that ...
7
votes
2answers
15k views

In a bash shell script, writing a for loop that iterates over string values

In bash, I know that it is possible to write a for loop in which some loop control variable i iterates over specified integers. For example, I can write a bash shell script that prints the integers ...
3
votes
2answers
138 views

Is there any way I can fit this into my ~/.bashrc as a function?

I just discovered this useful bit of code on this useful-looking website. #!/bin/sh exec tclsh "$0" ${1+"$@"} proc main {} { set lines [lrange [split [read stdin] \n] 0 end-1] set count ...
1
vote
2answers
723 views

Write to error stream in while loop

I’ve got approximately the following code: cat infile | while read line; do echo 2> 'log ' $line echo $line done > outfile outfile is created correctly. However, the STDERR output ...
3
votes
3answers
3k views

How to fix bash or auto run /bin/bash on SSH login

When logging in as root at my server everything works fine, but when I log in as myusername the bash is not working correctly. The line starts with: $ instead of myusername@myserver:~$ and all ...
4
votes
1answer
69 views

List the bash completion that's current active on a program?

Is there anyway to list the bash completion function in use for current command ? e.g for ls
2
votes
3answers
464 views

control number of started programs in bash

As part of my research project I'm processing huge amount of data splitted up into many files. All files in folder foo have to be processed by the script myScript involving all elements of folder ...
7
votes
3answers
2k views

My `which` command may be wrong (sometimes)?

I've compiled the last emacs version from the source code (v24.2) because the version installed on my machine is (quite) old for me (v21.3). I've done the usual: $configure --prefix=$HOME make make ...
3
votes
2answers
477 views

Are there any utilities to quickly add, list and remove command aliases?

I'd like to be able to quickly, on-the-fly add (and list/remove) command aliases so that they persist between shell restarts (as if they were added to .bashrc). Are there any ready ...
3
votes
2answers
641 views

How to enable local ~ autocompletion for scp?

Too late: The machine, OS and configuration in question is no longer in use, so I can't verify any more suggestions. I have not encountered this problem in Fedora or Arch Linux. If you are having this ...
0
votes
1answer
243 views

Pass output of a command as arguments to another(non-blocking)?

I was wondering how I can iterate over each line of the output of a command and pass it as command line arguments to another one. I want to do this in a non-blocking fashion as the output never ...
5
votes
3answers
2k views

How to set bash to run *.exe with mono?

Without any DE or even X, I want to use ./my.exe to run mono my.exe, like it works with python scripts.
4
votes
1answer
255 views

How does this git alias work?

Usually, git aliases are confined to a single command: git config --global alias.ci commit So, instead of git commit you could do git ci But it seems you can insert a function in there as well: ...