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
1answer
485 views

xmodmap equivalent in bash

I'm constantly on bash via ssh, on a computer that doesn't have X. In my computer I've switched the keyboards' Super and Alt keys with xmodmap. Is it possible to do it on the computer in which I log ...
7
votes
1answer
1k views

How can I alias to `!!` (last command)?

!! in bash runs last command. I find it too difficult to type given how much I use it. alias to the rescue, I presumed. Or not. I tried: $ alias dl='!!' # Aliasing $ echo Testing123 ...
0
votes
2answers
782 views

Bash script error trying to find directory of script itself: unexpected end of file

Borrowing graciously from this StackOverflow answer, I want to find the directory a script is running in so I can load relative paths for it on login: The script is pretty small right now: ...
3
votes
0answers
79 views

any way to un-disown / re-attach an interactive process to the tty? [duplicate]

Possible Duplicate: How can I disown a running process and associate it to a new screen shell? In bash is there an opposite of disown, that is, to re-attach a process I've accidentally ...
2
votes
3answers
589 views

Rename a lot of files with all types of characters, with POSIX portability

Sometimes I need to rename all the files (the renaming convention follows later) in a directory where the filename is always in the form of 'filenamename.extension' (extension always exists and ...
2
votes
1answer
1k views

Is there a shell utility for printing the contents of a plist? Preferably for a jailbroken iOS device?

I need a tool that prints the actual text in a plist file (plutil changes the format, cat prints gibberish, and there is no defaults command for iOS). It needs to be in a script, so text editors don't ...
7
votes
4answers
6k views

Diff several files, true if all not equal

I have a number of files, I want to check that all those files have the same content. What command line could I use to check that? Usage could be something like: $ diffseveral file1 file2 file3 ...
7
votes
4answers
2k views

Find files with same name but different content?

I want to generate a list of files that have: Same name Different content in a directory (including all children directories and content). How to do? Bash, perl, anything is fine. So, two ...
1
vote
2answers
4k views

How to write a file at various offsets to a filesystem partition with dd command

Requirement I want to write a file at various offsets into the partition Partition /dev/part2 is mounted at /mypart I tried the command below: dd if=/dev/urandom of=/mypart/aaa bs=1024 seek=0 ...
9
votes
2answers
1k views

Alternative to watch which support colors

I have a command (phpunit) which has a colored output. According to the watch, command I should be able to use the --color flag to allow color rendering to pass through. However, this isn't working. ...
1
vote
2answers
795 views

start apache script

I've got Apache installed on my local Linux (sabayon) OS, just for programming testing. What I want is a script so that the server starts right away when I want it. This is the code: #!/bin/bash # ...
3
votes
2answers
1k views

Change directory with -d in shell script

I am trying to give the option to the users to run the script in a different directory. However when the script changes the directory, the mkdir does not work. I change the directory like this: case ...
2
votes
2answers
435 views

Is it possible to define where the .bash_profile is located on the bash command line?

I'm running bash programmatically from objective c to create a terminal-like application. Once launched I would like to execute some commands prior to turning control over to the user. Normally these ...
0
votes
0answers
44 views

-d shell script doesn't work [duplicate]

Possible Duplicate: Change directory with -d in shell script I am trying to give the option to the users to run the script in a different directory. However when the script changes the ...
2
votes
3answers
196 views

is it possible to lock a user into a give directory tree in bash?

I want to lock a user into a given directory tree. That is he/she can cd deeper into the tree but no higher out of the tree. Everything else in the environment should be the exact same. Edit: How can ...
3
votes
2answers
1k views

What does this output from xev mean?

I'm interested in remapping some keys on my keyboard. In particular, I want to hold down the Function key, press the F1 key, and have this trigger a script. I know that xev is useful for figuring out ...
2
votes
1answer
132 views

Preventing LyX from getting a SIGHUP and closing when the terminal window is closed

I have written a Ruby script to manage my LyX documents. The script has a short CLI interaction with the user(=me), and then it decides the name of the file to open, and opens it via a lyx shell ...
21
votes
4answers
11k views

Can't use exclamation mark (!) in bash?

I'm trying to use the curl command to access a http url with a exclamation mark (!) in its path. e.g: curl -v "http://example.org/!287s87asdjh2/somepath/someresource" the console replies with bash: ...
23
votes
3answers
8k views

How to enable autocompletion for remote paths when using scp?

I remote copied a file to my laptop using: scp someFile USER@192.168.178.32:/home/USER/put/it/some/where/oh/damn/you/here I want to be able to autocomplete the remote path by hitting tab.
22
votes
3answers
2k views

Bash: repeat last N commands [duplicate]

In bash you can repeat the last command by entering !!, or the third last command !-3 for example. Is there a quick way to repeat the last 3 commands, without having to type out !-1; !-2; !-3 ...
6
votes
6answers
11k views

make grep output without trailing newline

Please consider this snippet: X=$(grep -m1 'some-pattern' some-file | sed -n 's/.* //p') I want to put last word in a variable if some pattern condition is matched for lines in arbitrary text file ...
2
votes
1answer
524 views

Configure autocomplete for the first argument, leave the others alone

I have a utility that takes a load of different arguments. For now, I want to autocomplete the first argument, but leave all the others to fall through to normal autocompletion. How do I do that? ...
4
votes
2answers
4k views

Can I redirect logfiles to syslog?

I have a Node.js server that is being monitored by forever. Forever generates three logfiles: the server STDOUT, STDERR and the log of forever itself. $ forever -l forever.log -o out.log -e err.log ...
14
votes
3answers
1k views

Bash scripting and large files (bug): input with the read builtin from a redirection gives unexpected result

I have a strange issue with large files and bash. This is the context: I have a large file: 75G and 400,000,000+ lines (it is a log file, my bad, I let it grow). The first 10 chars of each line is ...
3
votes
3answers
1k views

Check if filename exist from inline command

I have a file named input.txt with this contents: ... FILE "Edie - Realities.txt" TXT ... And I want to read it, then strip filename path from line that starts with FILE, and check if it ...
2
votes
1answer
606 views

Memory profiling the linux kernel on an embedded device

I have an linux kernel 2.6.30 on an ARM based embedded device and I have to do some kernel memory usage profiling on the device. I am thinking of monitoring the ps output on various kernel threads ...
5
votes
6answers
4k views

Linux script or program to shorten filenames

I haven't had much success in finding a Linux version of namemangler, which I need to rename 1000 of files so they are readable on Windows. Does anyone know of a Linux program that can do this? If ...
6
votes
2answers
449 views

Is it safe to remove a script file from within that script?

Imagine I have a script foo. It should be run once when the user logs in and isn't needed after a successful run. My question: Is it safe to remove the script file from within the script? E.g.: ...
14
votes
3answers
7k views

How to check if pipe is empty

I have piped line in bash script and want to check if pipe has data, before feeding program Searching I found about test -t 0 but it doesn't work here. Always returns false. So how to be sure that ...
7
votes
3answers
8k views

How to split the output and store it in an array?

This is the output: 3,aac-lc, 93.8, aaclc, 77.3, h.264, 1024.6, h.264, 1029.1, 31, 31, 0,0,0.000000,31,31,0,0,0.000000,7,0,0,0.000000,30,1280 720,10,0,0,0.000000,30,1280 720 I tried with 2 ...
10
votes
4answers
3k views

Have Bash script wait for status message before continuing

I'm firing up Selenium server with a bash script and as you can see from the timestamps on the log below, it takes about 32 seconds for the thing to fully come online: Feb 28, 2012 10:19:02 PM ...
3
votes
1answer
3k views

Real time system info script using ncurses and dialog

I'm trying to create a simple bash script that I can run over ssh that will display some basic system information using ncurses and the dialog command. I've tried two approaches so far: 1) Run dialog ...
4
votes
1answer
1k views

Use sed to fix broken newlines

I have a folder full of files, each with many hundreds of lines. Many of these files have occasional broken newlines: when I open them in vim, many have ^M^L interspersed where newlines should be. ...
1
vote
2answers
379 views

need portable crontab host-checking/failover logic across Linux & Cygwin

A host-ping test that always works correctly from the interactive bash command line in Cygwin, is behaving incorrectly in its own crontab--always selecting the second host--and I can't figure out why: ...
4
votes
3answers
354 views

Converting a history to a script?

Often times I've typed in a bunch of commands when I realize that I am going to keep typing them in and that I would really like a script. Now I understand that no matter how I save my history, I am ...
5
votes
1answer
445 views

history list in bash always truncated to 5000 lines at new login

Similar to the 5000 line limitation problem when first thing in .bashrc I have export HISTSIZE=10001 and export HISTFILESIZE=$HISTSIZE My users do not have ~/.inputrc files and the system-wide ...
1
vote
4answers
2k views

Count number of lines in files then compare which has more (BASH)

I need to count the number of lines in x files and compare which has more. The one I've done only takes two files and compares them. Any idea how to make it x amount of files? echo Enter the ...
3
votes
3answers
1k views

Extracting text from a text file in bash

I have a large text file that is all one line. In the text are several sections that looks like foo=12345 and I need to extract them all as separate lines, ignoring the rest of the file. For ...
4
votes
2answers
1k views

Excluding a file in bash loop

In the following script, How do I exclude a directory in the loop? I want to do this because all files are symlinks pointing to this directory that exists in the same level, so I don't want to add it. ...
0
votes
1answer
128 views

terminal logging doesn't complete when I close the terminal

This is the last line in my .bashrc (lines breaks inserted for readability): STARTTIME=`date +%F-%Hh-%Mm-%Ss-%N`; \ script -q -t 2> /home/USER/logs/$STARTTIME-timing.txt \ -c 'bash --rcfile ...
1
vote
4answers
659 views

Exporting environment variable

I am having some problem with bash. I want to export an environment variable whose value contains a variable but I don't want that variable (which is within the value) to be evaluated during the ...
3
votes
2answers
22k views

Auto running bash script on login

I wanted to make a script which ran automatically on login so I put it into the file ~/bash.profile, but it didnt run. When I put it in bashrc, it ran on opening a terminal. What I was doing in the ...
3
votes
2answers
1k views

Insert a multiline string into another string

I need to insert lines into an xml file : Insert <one> </one> into <tags> </tags> To obtain <tags> <one> </one> </tags> I tried this: ...
1
vote
2answers
341 views

Variable name from command output

I have some string, and want to split on colon ":" assigning on variable with name from left part and value from right part. For example: echo "Title: Some title" | sed 's/:.*//' gives me wanted ...
3
votes
3answers
222 views

How to perform an action only on the first line?

sed 's/.\(.*\)/\1/' myfile Say myfile contains: abc def ghi I want to remove the first character only from the first line but the above removes it from all the line.
10
votes
6answers
5k views

How can I open a new terminal in the same directory of the last used one from a window manager keybind?

I'm using a tiling window manager and I switched from gnome-terminal with multiple tabs to multiple urxvt instances managed by the window manager. One of the features I miss is the ability to open a ...
15
votes
3answers
2k views

Excluding some of the commands from being getting stored in bash history

Is there any way to exclude commands like rm -rf, svn revert from being getting stored in bash history? Actually I, by mistake, have issued them a number of times even though I have no intent to do, ...
5
votes
4answers
8k views

What are the different ways that a message can be displayed to a bash shell after a user logs in?

I have a CentOS 5.7 VPS using bash as its shell that displays a branded greeting immediately after logging in via SSH. I've been trying to modify it, but can't seem to find where it is in the usual ...
17
votes
3answers
2k views

Set and Shopt - Why Two?

set and shopt are both shell builtins that control various options. I often forget which options are set by which command, and occasionally which option sets/unsets (set +o/-o, shopt -s/-u). Why are ...
0
votes
5answers
102 views

When I set the default shell, it doesn't “take”

I want my default shell to be bash. However, whenever I log into my server, the shell is apparently -bash: $ echo $0 -bash If I run bash, I'm of course switched to bash for that session, but it ...