Tagged Questions

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

2
votes
2answers
6k views

Multiple path environment variable setup lines with bash

I have very long export PATH=A:B:C .... Can I make a multiple lines to have more organized one as follows? export PATH = A: B: C:
4
votes
2answers
986 views

Why can't I pgrep a process?

$ ps aux | grep -i ssh USER 4364 0.0 0.0 9004 1032 ? Ss 12:20 0:00 ssh -v -fND localhost:4000 USERNAME@SERVER-IP-ADDRESS $ pgrep localhost:4000 Why doesn't this work?
10
votes
4answers
3k views

Batch delete exif info

How can I recursively remove the EXIF info from several thousand JPG files?
2
votes
1answer
472 views

Is there some kind of “patterns” when coding bash scripts? [closed]

In Java, we have Javadoc and some different styles when programming. In Python, there's pep8. I'm creating some bash scripts for my own use, and would like to know from you, experienced bash users, ...
4
votes
2answers
3k views

In bash, how to convert 8 bytes to an unsigned int (64bit LE)?

How can I 'read/interpret' 8 bytes as an unsigned int (Little Endian)? Perhaps there is a Bash-fu magic conversion for this? UPDATE: It seems that something got cross-wired in the interpretation of ...
1
vote
1answer
141 views

How to bash-complete output of two arbitrary commands at the same time

Here goes: function _command() { local cur COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} if [ "$COMP_CWORD" -ge "2" ]; then COMPREPLY=($( compgen -W '$(pwd)' -- "$cur" ) ) ...
3
votes
1answer
3k views

auto accepting rsa key in bash script

I have done a little googling and have not come up with a clear answer to this question. I was wondering if someone could help me out with this issue. Is there a way to auto accept any RSA key inside ...
5
votes
1answer
4k views

Dollar sign interpolation inside quotes in bash

I am running this little test script I wrote : #!/bin/bash TESTCASE=$@ testHarness <<runTest $TESTCASE runTest from the command line : ./test.sh "1092$212" but the dollar sign is being ...
5
votes
2answers
6k views

loop curl get request bash

I'm trying to automate a curl script and eventually make it loop also. I found that I can't use any loop like: for i in `cat authors` do curl *line here* ...
2
votes
2answers
380 views

bash quotes expansion puzzle

My script looks like: opts="-x ''" curl http://somepage $opts I want the string in $opts appended to the command. I use bash -x test.sh to check the expansion and see that the the single-quotes are ...
3
votes
1answer
254 views

Preventing use of `cd ..` in bash?

I have set up an alias in my .bashrc as follows: alias u='cd ..' All is well in my world... until I type cd .. and cringe that I did not use my incredible new alias. In fact, with this particular ...
1
vote
2answers
687 views

writing a command transcript to file

Here is a script from Mercurial issue 2743. Call it mq.sh. I'm trying to get it to do the following things, on Debian squeeze. Echo commands + standard output + standard error to a file. Prefix with ...
14
votes
2answers
833 views

How can one time out a root shell after a certain period of time?

Is there a way to 'time out' a root shell (for example, in gnome-terminal) so that after a certain amount of time not issuing any commands, the shell exits? I'm searching for a solution that works in ...
1
vote
1answer
323 views

How to have autocomplete ignore a specific completion

I've got auto-completion working for bash. When I type part of a program name, and then TAB, I get the full command. Works like expected, no complaints. However on my setup I've got an alias defined ...
5
votes
2answers
877 views

Will I be able to build LFS using dash and mawk?

I decided that I want to learn more about Linux and try building LFS. I'm using Ubuntu 11.04 as host system and Ubuntu uses dash and mawk by default. I've changed mawk to gawk, but considering that ...
3
votes
1answer
364 views

BC - output normal form?

I have a big number: 2923174917395723957 that would be: 2,923*10^18 are there any parameters in bc that will give this OUTPUT? e.g.: $ echo '2923174917395723956 + 1' | bc 2,923*10^18 $ Or ...
2
votes
4answers
754 views

BC - no “\\n” at the end + start with zeros?

This is a bc output, e.g.: Input: echo "scale=10; BLA-BLA-HERE-NOT-IMPORTANT" | bc Output: .3708446283953709207058828124021300754352578903651372655882743141882\ ...
14
votes
2answers
8k views

How to get the output inside `screen` out to a script?

I have a screen instance running, and I would need to execute some code inside the screen, and get the result out to my script. The first part is quite easy, I just screen -S session_name -X eval ...
10
votes
5answers
2k views

Weird Stuff in Terminal When I Hit Tab

For some reason, today, everytime I hit tab in the terminal this shows up: cat bash: warning: setlocale: LC_CTYPE: cannot change locale (en_CA) Display all 150 possibilities? (y or n) This ...
2
votes
1answer
239 views

Switch back to path when resume job from background

Say I open ~/vim.txt, push that to background, then cd to another path. When I bring that job to foreground, is there an option to switch back to old path? I noticed it says pwd, so I assume it is ...
35
votes
6answers
4k views

Can I configure my shell to print STDERR and STDOUT in different colors?

I want to set my terminal up so stderr is printed in a different color than stdout; maybe red. This would make it easier to tell the two apart. Is there a way to configure this in .bashrc? If not, is ...
4
votes
2answers
550 views

Directory special permission problem

When I write: chmod g=rws,u=rwx,o=rx folder_name I get: drwxrwSr-x But S is not the same as s, right?
20
votes
3answers
2k views

How does TAB auto-complete find options to complete?

And how does it also autocomplete aliases?
3
votes
3answers
1k views

How to customize .bashrc to configure command prompt?

Is there an easy way to change my Bash prompt to modify the colors and what text is displayed? I've heard that this is done in .bashrc, but I haven't found any nice, easy ways of modifying it. How are ...
6
votes
1answer
329 views

Can I have my shell history record how wildcards expanded?

If I run: $ ls * foo bar buzz $ history | tail -1 ls * You can see that in my shell history it remembers that I ran ls * rather than ls foo bar buzz. Ideally, I'd like to record both in separate ...
11
votes
4answers
7k views

In bash, how can I convert a Unicode Codepoint [0-9A-F] into a printable character?

I have a list of Unicode codepoints, but I don't know of a "simple" way to convert these hex values into the actual characters they represent... I've heard that zsh has echo -e '\u0965', but I use ...
31
votes
4answers
3k views

unix, difference between path starting with '/' and '//'

In unix/linux, any number of consecutive forwardslashes in a path is generally equivalent to a single forwardslash. eg. $ cd /home/shum $ pwd /home/shum $ cd /home//shum $ pwd /home/shum $ cd ...
4
votes
3answers
6k views

checking an argument to a bash script is a string of all digits

The Bash FAQ says If you're validating a simple "string of digits", you can do it with a glob: # Bash if [[ $foo = *[!0-9]* ]]; then echo "'$foo' has a non-digit somewhere in it" else echo ...
15
votes
5answers
5k views

Best resources to learn bash scripting?

I've programmed in a number of languages for two years now, I mean that I know how to design and implement a decent solution for a given problem. However, bash is being a major headache to me, just ...
3
votes
6answers
4k views

ssh user@IP sh <command> missed environment variables

I use an approach ssh user@IP sh [runme.sh] to execute script remotely, this works fine. But I got one problem, that is in runme.sh, I can't get any envirnoment variables which are defined in ...
4
votes
2answers
765 views

bash script is trying to execute a variable

I have a very short Bash script, like this: variable="3 things" if $(echo $variable|grep "^[0-9]\{1,\}") #if $variable begins with [0-9] then echo $(echo $variable|sed 's/ .*$//') else echo ...
7
votes
1answer
343 views

Does one alias affect another alias?

I don't have many aliases set up in my .bash_aliases file just yet. Only recently have I discovered how useful they can be. I can see myself getting quite hooked on aliases so before the file gets ...
16
votes
3answers
31k views

How to measure time of program execution and store that inside a variable

In order to find out how long certain operations within a Bash (v4+) script take, I would like to parse the output from the time command "separately" and (ultimately) capture it within a Bash variable ...
8
votes
4answers
617 views

Forcing an 'added' alias to every command

Is it possible to forcibly add a timing alias (for lack of a better way to phrase it) to every command in bash? For example, I would like to have a specific user who whenever a command is run, it is ...
5
votes
4answers
1k views

Is there any book , Tutorial on very very advanced shell scripting [closed]

I am looking for some tutorial where a simple script is written using very advanced methods so that i can learn more from
2
votes
1answer
145 views

Is there a program which gives the X screen co-ords of the Text-cursor (insertion point)?

xdotools gives the ability to insert text at the current text insertion point, but it doesn't seem(?) to have an option which gets the actual screen x,y co-ordinates... Is there any such program? ... ...
13
votes
2answers
879 views

Copy and set-mark in Bash as in Emacs?

I would like to be able to copy and paste text in the command line in Bash using the same keyboard bindings that Emacs uses by default (i.e. using C-space for set-mark, M-w to copy text, C-y, M-y to ...
7
votes
2answers
722 views

What is a good way of saying “run this after 15 minutes” on a shell?

I use this sleep 900; <command> on my shell. Just wanted to know is there is some alternate/better way that you use?
10
votes
2answers
393 views

How to use - as alias?

When I was using openSUSE 11.3, it came with several aliases already set up. Two that I used a lot were + for pushd . and - for popd. Now on Debian, I can't figure out how to create the second one. ...
3
votes
2answers
772 views

How to change the target directory for tab completion?

I found a short script to enable note-taking on onethingwell, which includes this: function n { nano ~/n/$1.txt } I'd like to extend it to do tab completion, so that if I want to edit the ...
13
votes
3answers
2k views

How can I tell bash valid tab-completions for arguments to my Python script

Say I have a program hello.py and one possible valid argument to it is: ./hello.py autoawesomesauce Is is possible to type in: ./hello.py auto[tab] at which point the partially completed ...
3
votes
2answers
1k views

How to map one vim command to execute bash commands based on OS?

In short, can single bash commands in the terminal contain conditionals? If so, how? I have in my vimrc (shared across systems) the following command to open my current LaTeX document in .pdf form: ...
2
votes
1answer
910 views

how to detect a laptop hibernate/resume(close lid,open) in osx from a bash script

This is a follow on question to how to trap a suspend a resume from a bash script How do you a trap the event that occurs when you close the lid and later reopen it from a bash script?
1
vote
1answer
662 views

Bind key to a bash script

I'm trying to bind a key (now without function) to a bash script that I have made on Ubuntu. I'm using a clevo W150HNM/Sager NP5160 I want to use button 1 or 4 for this. (see photo) I don't get any ...
4
votes
2answers
503 views

Sudo no longer available and users can't install or modify most files

I recently started messing with some files on a virtual hosted machine and I was logged in a normal/non-root user. At first everything was fine, I was able to install anything I needed using: sudo ...
5
votes
2answers
1k views

Alternative to su/sudo on barebone system

I'd like to run some unit tests in a barebone chroot jail on Solaris. There's no su or sudo, and a copy of su (with libpam.so.1) just returns exit code 1 without any output, with or without ...
2
votes
1answer
2k views

Cron daemon error : Permission Denied

I am having trouble setting up a cron job. My set up is as follows: crontab -e */10 * * * * OTP_ProJect/PandaServerInfo/SVN/PandaQueueMonitoring/trunk/submit_cron_test.sh the shell script has ...
3
votes
7answers
1k views

How to write repeated free-form strings to a file, as fast as 'dd'?

dd can write repeating \0 bytes to a file very fast, but it can't write repeating arbitary strings. Is there a bash-shell method to write repeating arbitary strings equally as fast as 'dd' (including ...
32
votes
4answers
3k views

What is the difference between a builtin command and one that is not?

Is there any intrinsic difference between a builtin command and another command which can nominally do the same thing? eg. Do builtins get "special" treatement? ... is there less overhead running ...
4
votes
1answer
3k views

Why is 'while.. read.. <<EOL' performing variable expansion, yet <file and | don't?

Aside from the variable expansion mentioned in the question's heading, I also experience another alarming issue when reading inline data to <<EOL... When the data contains a backtick `, it ...