bash

Translate parse_git_branch function to zsh from bash (for prompt)

I am using this function in Bash function parse_git_branch { git_status="$(git status 2> /dev/null)" pattern="^# On branch ([^${IFS}]*)" if [[ ! ${git_status}} =~ "working directory clean" ]]; then state="*" fi # add an else if or two here if you want to get more specific if [[ ${git_status} =~ ${pattern} ]]; then b...

Running lame from php

I am trying to run lame from a php script. I have tried these, but no luck, I don't get anything returned! Any ideas? system('lame', $returnarr); system('lame --help', $returnarr); exec('lame', $returnarr); passthru('lame', $returnarr); even this one returns nothing: exec('which lame', $returnarr); I am on OSX and final deployment...

Get list of Python module variables in Bash

For a Bash completion script I need to get all the variables from an installed Python module that match a pattern. I want to use only Python-aware functionality, to avoid having to parse comments and such. ...

bash tools for parsing arguments

I have a bash script that uses a few variables (call them $foo and $bar). Right now the script defines them at the top with hard coded values like this: foo=fooDefault bar=barDefault .... # use $foo and $bar What I want is to be able to use the script like any of these: myscript # use all defaults myscript -foo=altFoo ...

What scripts should not be ported from bash to python?

I decided to rewrite all our Bash scripts in Python (there are not so many of them) as my first Python project. The reason for it is that although being quite fluent in Bash I feel it's somewhat archaic language and since our system is in the first stages of its developments I think switching to Python now will be the right thing to do. ...

Linux read command - simple question

Hi, why is output empty? echo "a b c d" | read X Y Z V; echo $X Thanks. ...

In a bash script echo shell commands

In a bash script how do I echo all shell commands called and expand any variable names? For example, given the following line: ls $DIRNAME I would like the script to run the command and display the following ls /full/path/to/some/dir The purpose is to save a log of all shell commands called and their arguments. Perhaps there is a bet...

How do I pass the resulting files from one grep pass to another so that I only grep through the subset with the second pass?

Hello All, I want to be able to take the files I found with my first grep statement, something like this for example: grep -r Makefile * And then pass the files found in that pass of grep to a second grep with something like this for example: grep {files} '-lfoo' How do I do this? I know there must be a way. Thank you. ...

Command to escape a string in bash

I need a bash command that will convert a string to something that is escaped. Here's an example: echo "hello\world"|escape|someprog Where the escape command makes "hello\world" into "hello\\world". Then, someprog can use "hello\world" as it expects. Of course, this is a simplified example of what I will really be doing. ...

Get KDE to run a bash script.

I have a bash script that takes a file name as an arg. It works great from the command line. When I right-click a file in KDE and select "open with", then point it to my script, it doesn't run. What am I doing wrong? ...

Resolve bash variable containted in another variable

I have code like that: TEXT_TO_FILTER='I would like to replace this $var to proper value in multiline text' var=variable All I want to get is: TEXT_AFTER_FILTERED="I'd like to replace this variable to proper value" So I did: TEXT_AFTER_FILTERED=`eval echo $TEXT_TO_FILTER` TEXT_AFTER_FILTERED=`eval echo $(eval echo ...

Problem with Ruby script output being stored into a file

I have a Ruby script that outputs a heap of text. As an example: puts "line 1" puts "line 2" puts "line 3" # etc... (obviously, this isn't how my script works..) There's not a lot of data - perhaps about 8kb of character data in total. When I run the script on the command line, it works as expected: $ ./my-script.rb line 1 line 2 l...

Execute a BASH command in Python-- in the same process

I need to execute the command . /home/db2v95/sqllib/db2profile before I can import ibm_db_dbi in Python 2.6. Executing it before I enter Python works: baldurb@gigur:~$ . /home/db2v95/sqllib/db2profile baldurb@gigur:~$ python Python 2.6.4 (r264:75706, Dec 7 2009, 18:45:15) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "...

Bash: any command to replace strings in text files?

I have a hierarchy of directories containing many text files. I would like to search for a particular text string every time it comes up in one of the files, and replace it with another string. For example, I may want to replace every occurrence of the string "Coke" with "Pepsi". Does anyone know how to do this? I am wondering if there i...

Script to parse emails for attachments

I am looking for a way to monitor a Linux mbox email account, when an email arrives I would like to download an attachment from the email and save the attachment (CSV file) so that it may be used by a PHP script. What would be the best way of going about this? I have looked at PHP's IMAP functions but this does not appear to be the most ...

"This Friday" in bash script

Hi, Is there a way to calculate a time stamp for the next coming up of a week day? So for instance, with friday, i'd like to be able to run some code that calculates that from today Wednesday 19/05/10, the next friday will be 21/05/10 and get a time stamp from it. I know the date command can parse a given string date according to a f...

How to send a keystroke to a x11 vnc session (xtightvncviewer)

I need to press a ceratin Key after setting up a server connection via xtightvncviewer in order to make an automated screenshot. Can i pass it with the startupscript? ~/VNC# xtightvncviewer myserver.dyndns.org -bgr233 -passwd /root/.vnc/passwd ...

Convert GNU find command to Python function

I want to convert this GNU command into a python function: find folder/ 2>/dev/null > file.txt The find will list all files and folders from the directory recursively and write them to a file. What I have now in Python is: import os project="/folder/path" i=0 for (project, dirs, files) in os.walk(project): print project print ...

Including/Importing aliases and functions for both bash and zsh

I have a directory of functions and aliases I'd like to include for both bash and zsh terminal invocations (So I don't need to put every function and alias into every separate script and to facilitate organization/tidying of .rc files) What I've tried so far hasn't worked. Just setting this out for further suggestions. ...

add string after each line bash

How do I add a string after each line in a file using bash? Can it be done using the sed command, if so how? ...