bash

What is the best (portable and maintanable) Shell Scripting language today?

Hi All, I know this question has kind-a started "religious" wars in past and there might not be one correct answer. But after working with ksh and csh for last 3-4 years and going through the pain of porting from one to another or applying a common piece of logic to multiple versions (read as legacy code), if I am writing a new script, ...

what's the difference between foreground and background programme?

I tried to run a programme in background mode and foreground mode, while in background mode,it failed to run, but in foreground mode,it succeeded, so what's the difference between background and foreground mode that might cause this issue? ...

Grep Recursive and Count

Need to search a directories with lots of sub-directories for a string inside files: I'm using: grep -c -r "string here" * How can I total count of finds? How can I output to file only those files with at least one instance? ...

what does these output mean?

especially the last two with '-' and '+' respectively, what does it mean on earth? [1] Done php start.php bots/admin32.bot.php [2] Done php start.php bots/admin36.bot.php [3] Done php start.php bots/admin10.bot.php [4] Done php start.php bots/admin11....

In bash, how can I print the first n elements of a list?

In bash, how can I print the first n elements of a list? For example, the first 10 files in this list: FILES=$(ls) UPDATE: I forgot to say that I want to print the elements on one line, just like when you print the whole list with echo $FILES. ...

Why does this sed command do nothing inside a bash script but work outside?

# join pairs of lines side-by-side (like "paste") sed '$!N;s/\n/ /' The above script comes from the great list of sed one-liners found on sourceforge. I wish to use it in an a bash script but it has no effect if used inside the script. If I pipe the output of the script through it, it joins join pairs of lines side-by-side as descri...

Run MySQL Query after wget finishes downloading file

I need to run a specific mysql query upon wget, which is running in the background, finishes downloading a file. For example... wget http://domain/file.zip then run: UPDATE table SET status = 'live' WHERE id = '1234' How would I go about doing this? ...

Unable to refer to a parameter in Bash

I want to put TextA to the beginning of TextB by cat TextA A TextB The problem is that I do not know how to refer to the first and second parameters, that is TextA and TextB in the following script called A: #!/bin/bash cat TextA > m1 cat TextB > m2 cat m1 m2 > TextB where m1 and m2 are temporary files. How can you refer ...

BASH blank alias to 'cd'

I am a happy BASH user. I do not want to switch to another shell (in this case ZSH). ZSH has this ability to change a directory without necessarily typing: cd /to/a/directory What would the correct alias (or maybe BASH function) to change directories without having to type 'cd'? On my above example, moving to /to/a/directory would b...

Integer ASCII value to character in BASH using printf

Character to value works: $ printf "%d\n" \'A 65 $ I have two questions, the first one is most important: How do I take 65 and turn it into A? \'A converts an ASCII character to its value using printf. Is the syntax specific to printf or is it used anywhere else in BASH? (Such small strings are hard to Google for.) ...

Unable to add a parameter to your command in Bash

I have the following code which I call google #!/bin/bash q=$1 open "http://www.google.com/search?q=$q" It opens Firefox with the keyword. For example, by google cabal I want to have specific keywoards added to the command when I put a parameter after the command. The following is an example google -x cabal It searches the sequ...

Unable to have Bash-like C-x-e in Zsh

I found the following command in Bash which Zsh does not have in the same buttons at the thread. Ctrl-x-e It opens the current input in terminal to an editor. How can you have the same command in Zsh? ...

bash script to ssh into a box and get me to a python shell

I want to write a script that will get me straight to a python shell on another box so that i don't have to first run ssh and second run python. When I do "ssh hostname python" it just hangs - it's something to do with the fact that python is interactive. "ssh hostname cat x" works fine. Is there some ssh option that will make this wor...

Putting the output of a command with interaction inside a variable while using grep in bash

This program I use has it's own variables to set when you run it, so I want to set those variables and then greping the output then storing it inside a variable. However, I don't know how to go about this the correct way. The idea I have doesn't work. The focus is on lines 7 through 14. 1 #!/usr/local/bin/bash 2 source /home/gempak/NA...

How to parse XML in Bash?

Ideally, what I'd like to be able to do is: cat xhtmlfile.xhtml | getElementViaXPath --path='/html/head/title' | sed -e 's%(^<title>|</title>$)%%g' > titleOfXHTMLPage.txt ...

Multi-server monitor/auto restarter in python

I have 2 server programs that must be started with the use of GNU Screen. I'd like to harden these servers against crashes with a Python based program that kicks off each screen session then monitors the server process. If the server process crashes, I need the python code to kill the extraneous screen session and restart the server with...

Open files in existing Gvim in multiple (new) tabs

I have put some aliases in my .bashrc to open a group of project files in gvim, each in their own tab: gvim -p <list of file names using absolute paths> This is all well and good, except there are several groups of files I might want to move between at any given time (my current project uses Ruby on Rails, so that explains that). Wha...

How to pipe a command result to a -<character><argument> option? (Without spaces)

Hello! I have this set of piped commands: grep -n '*' file.txt | head -n1 | awk -F\: '{print $1-1;}' It tells me the previous line to that where it first find asterisks. Now I want to get the previous lines piping that to: head -n<that previous line number> Head requires a number following immediately the -n argument, without space...

Gnu-Screen: Run script that sends commands to the screen session it is being run in.

Is it possible to write a script to change the name and turn on monitoring for the current tab assuming that it is being run in screen? Thanks. ...

about .bash_profile, .bashrc, and where should alias be written in?

it seems that if i use alias ls='ls -F' inside of .bashrc on Mac OS X, then the newly created shell will not have that alias. I need to type bash again and that alias will be in effect. and if i log into linux on the hosting company, the .bashrc has a comment line that says: for non-login shell and .bash_profile has a comment fo...