bash

How do I change bash history completion to complete what's already on the line?

Hi there, I found a command a couple of months ago that made my bash history auto-complete on what's already on the line when pressing the up arrow: $ vim fi [press up] $ vim file.py I'd like to set this up on my new computer, because it saves a lot of time when keeping a big history. The problem is that I can't for the life of me r...

how to chop last n bytes of a string in bash string choping?

for example qa_sharutils-2009-04-22-15-20-39, want chop last 20 bytes, and get 'qa_sharutils'. I know how to do it in sed, but why $A=${A/.{20}$/} does not work? Thanks! ...

How can I access variables that are named sequentially by a loop while still inside of the loop?

I'm trying to understand if it's possible to create a set of variables that are numbered based on another variable (using eval) in a loop, and then call on it before the loop ends. As an example I've written a script called question (The fist command is to show what is the contents of the variable $tab) (23:32:12\[[email protected]) [~/bin]$ ...

sed to replace random site urls in ifrrame

Hello, my problem there is alot of pages infacted with iframe each one of them have different url or different id here is example <iframe src="http://xxxxxx.xxxx/xxxx.xxx" width=xxx height=xxx style="visibility: hidden"><iframe> or <iframe src="http://xxxxxx.xxxx/xxxx.xxx?xxx=xxxx" width=xxx height=xxx style="visibility: hidden">...

How do I use the bash time function from python?

I would like to use python to make system calls to programs and time them. From the Linux command line if you type: $ time prog args You get something along the lines of: real 0m0.110s user 0m0.060s sys 0m0.024s if you do a 'man time', it states that you can type: $ time -f "%E" prog args in order to format to get only...

bash shell script syntax error

I wrote a function in bash script. However, it's complaining about syntax. I really can't see what is it..... the error message is [: missing `]' addem() { if [ $# -eq 0] || [ $# -gt 2 ] then echo -1 elif [ $# -eq 1 ] then echo $[ $1 + $1 ] ...

zip columns from separate files together in bash

I have two files which both contain a list of words. Is there an easy way to zip the contents of the files into one new file in bash, so that the resultant file would have two columns like this: file1_line1 file2_line1 file1_line2 file2_line2 file1_line3 file2_line3 file1_line4 file2_line4 ...

Prefered terminal scripting language

What language do you prefer writing scripts for common tasks (backup, sync, etc.) and why? I'm not talking about programing web pages or applications. I've got this question when thinking why bash is still popular. For example python looks more comfortable for me. Do you use just because you know it or for some special reasons? ...

Running BASH script from iPhone app?

Basically I am wondering if it is possible to run a console script (.sh) from an iPhone App. The script is written to download a program from a repository that I set up, respring, then after a set time delete the program and respring again, so it needs root privileges, and is interactive in that the user can set how long the program will...

Different bash prompt for different vi editing mode?

When using vi mode (set -o vi) with Bash, it would be nice to have a prompt that depends on the mode you are currently in (insert or command). How does one find out this editing mode? B.t.w, this seems to be possible in ZSH: ...

Bash shell script to flip through directories and perform a few actions

Good afternoon, I have a question about a script I am having problems with. I did something similar a couple of years ago and based this on that (which was on a different server). I need to run the script from a directory that has a number of directories in it and for each directory have it create a directory and change it's ownership....

How do I can linux flock command to prevent another root process deleting a file?

Hello there, I would like to prevent one of my root process from deleting a certaing file. So I came across the flock command, it seems to fit my need, but I didnt get its sintax. If I only indicate a shared lock, it doesnt work: flock -s "./file.xml" If I add a timeout parameter, it still doesnt work flock -s -w5 "./file.xml" It ...

Unable to make a if-else loop for google-books in Bash

My current code #!/bin/bash #w=$2 #e=$3 #r=$4 #t=$5 #o=$5 # prepend="" append="" case "$1" in -h) echo 'Usage: google [-{hxdw}] [<arg>]' echo ' -h: show help.' echo ' -x: search for "<arg> is"' echo ' -d: search for "define:<arg>"' echo ' -w: search for <arg> site:wiki...

echo printing variables on single line

I have two variables declared as follows: export portNumber=8888^M export loginIP_BASE=10.1.172.2^M I'm trying to print them both on a single line seperated by a colon ':' with the following script. It should look like "10.1.172.2:8888" echo -n 'Login IP:' echo -n $loginIP_BASE echo -n ':' echo $portNumber but it it prints out the ...

Getting the pid of a job launched in the background remotely

I am trying to launch in the background a job on a remote machine and get its PID so that I can kill it later on. What I have come up with so far is the following: #!/bin/bash IP=xxx.xxx.xxx.xx REMOTE_EXEC="ssh $IP -l root" # The following does NOT work, I am trying to get the PID of the remote job PID=`$REMOTE_EXEC 'vmstat 1 1000 > v...

Bash: Getting standard program for file type

Hi, the background is a shell script to open the .m3u file of a web radio station. Therefore I want to know inside the script, what's the user's program to open such files. At the moment, he has to set the environment variable $PLAYER, but obviously that is not a good way to go. Alternative: Is there a command that takes a filename and...

How can I re-add a unicode byte order marker in linux?

I have a rather large SQL file which starts with the byte order marker of FFFE. I have split this file using the unicode aware linux split tool into 100,000 line chunks. But when passing these back to windows, it does not like any of the parts other than the first one as only it has the FFFE byte order marker on. How can I add this two ...

Using 'expect' to automatically send in password

I am trying to copy a file from my remote server to my local. Here's my script to run it, by using 'expect' to automaticlally send in password scp user@host:/folder/myFile ./ expect "Password: " send "myPassword" When I run this, it still prompts for "Password", what is wrong? ...

How to split flv file by size using FFmpeg or mencoder or smth else?

I need to split an flv file into chunks of the known size on linux server. For example my original file is 9Mb and the chunk size is 4Mb. So I should get 3 parts - 4Mb, 4Mb and 1 Mb. Seems that FFmpeg can split only by time. Mencoder can start by time (-ss TIME) and finish by size ( -endpos SIZE MB). But if start second of the first ch...

Shell script to extract particular content using find, xargs, and grep

Hi everyone. Well i am new to linux shell and i can't understand any regexp :( Here is my question: I have a directory called /var/visitors and under this directory, i have directories like a, b, c, d. In each of these directories, there is a file called list.xml and here is the content of list.xml belonging to /var/visitors/a directory...