bash

Bash script absolute path with OSX

I am trying to obtain the absolute path to the currently running script on OS X. I saw many replies going for readlink -f $0. However since OS X's readlink is the same as BSD's, it just doesn't work (it works with GNU's version). Any suggestions for an out of the box solution to this? ...

fit syntax from bash to ksh

hi all the following syntax work in bash but bot work on ksh script [[ " $LINE_FROM_FILE " == *[![:alnum:]]Validation[![:alnum:]]* ]] && print "find Validation word" can someone have idea how to change the syntax in order to fit also ksh script remark: the target of this syntax to verify if Validation word exist in $LINE_FROM_FI...

How to share bash/shell code snippets taken from command prompt with syntax coloring

Hi there. I'm looking for some way to share code snippets taken directly from command prompt. For example: plinjasa@pllzpc029 ~ $ ls plinjasa@pllzpc029 ~ $ mkdir maindir plinjasa@pllzpc029 ~ $ ls -l total 0 drwxr-xr-x+ 1 plinjasa Domain Users 0 2010-08-26 15:22 maindir plinjasa@pllzpc029 ~ $ cd maindir plinjasa@pllzpc029 ~/maindir ...

Difference between "echo 'hello'; ls" vs "echo 'hello' && ls"?

I wonder what the difference between "echo 'hello'; ls" and "echo 'hello' && ls" is? they both do the same thing ...

match word with letters in shell script

hi all I need to verify if the second word from $line_from_file is a string with lowercase or uppercase characters (WORD - string can be with numbers) How to match WORD string? (I use this syntax in ksh script) [[ ` echo $line_from_file | awk '{print $2}' ` = WORD ]] && print "MATCH" WORD - can be small or capital chara...

shell script + short syntax to verify valid IP

hi all my question is , I want to get some short and smart ideas to verify the IP address then my example Maybe some perl syntax that I can combine in my ksh script lidia ...

Iterate through parameters skipping the first

Hi i have the following: bash_script parm1 a b c d ..n I want to iterate and print all the values in the command line starting from a, not from parm1 ...

Iterate through command line parameters and append to string

I have ./basscript parm1 parm2 parm3 I want to iterate through the parms starting from parm2 till parmN and append them to a variable. How do I get ${COMPLETE}="parm1,parm2,parmN"? ...

Visually distinguishing between local and remote Terminal sessions

I'm using Terminal under OS X quite extensively. I find quite annoying (and a bit dangerous, too) that my local and remote sessions look exactly the same in the Terminal. I'm wondering if it's possible - maybe through a bit of bash-programming - to clearly distinguish between local and remote sessions. A different background color would...

How to re-write powershell code in bash

I've been tasked with re-writing this in bash. But whilst most powershell is easy to read, i just dont get what this block is actually doing!!? Any ideas? It takes a file which is sorted on a key first, maybe thats relevant! Thanks for any insights! foreach ($line in $sfile) { $row = $line.split('|'); if (-not $ops[$row[1]]) { ...

How to determine which directory a link is pointing to using bash

With Bash scripting, is there a way to determine which directory a link is pointing to, then switch it to another directory based on the result? For example, say I have the two following directories: /var/data/1/ and /var/data/2/ I have a link to one of them, say, data_link and it is currently linked to /var/data/1/ When the script i...

How to tee into fd's instead of named pipes.

I want to take stdout of a process and analyze it with three different programs. I have been able to use named pipes, but can I use fd's instead. Here's what works so far: exec 3< <(myprog) tee p1 p2 >/dev/null < <(myprog) tee >...

Git GUI to checkout single file

I have several version of project stored under GIT.. Now my requirement is that I need to get one specific file from one of the previous version. Reading this forum I came to know that it can be done by Git Bash. Is there a way to checkout one particular file using Git GUI Thanks in advance ...

bash: how to delete elements from an array based on a pattern

Say I have a bash array (e.g. the array of all parameters) and want to delete all parameters matching a certain pattern or alternatively copy all remaining elements to a new array. Alternatively, the other way round, keep elements matching a pattern. An example for illustration: x=(preffoo bar foo prefbaz baz prefbar) and I want to d...

How do I Select Highest Number From Series of <string>_# File Names in Bash Script

I have a directory with files heat1.conf heat2.conf ... heat<n>.conf minimize.conf ... other files.... I want my Bash script to be able to grab the highest number filename (so I can delete and replace it when I find an error condition). What's the best way to accomplish this? Please discuss the speed of your solution and why you thi...

Automatic input in Ruby script?

Im running this command from ruby script: system "trad install" This will prompt me three times for choosing y/n. Is there a way to automatically choose y,y,n? ...

How do you climb up the parent directory structure of a bash script?

Hello, Is there a neater way of climbing up multiple directory levels from the location of a script. This is what I currently have. # get the full path of the script D=$(cd ${0%/*} && echo $PWD/${0##*/}) D=$(dirname $D) D=$(dirname $D) D=$(dirname $D) # second level parent directory of script echo $D I would like a neat way of fin...

What does the $# construct mean in bash?(and in general I suppose)

I see foo() { if [[ $# -lt 1 ]]; then return 0 fi ... } What exactly is it comparing by using $# as it does there? ...

Merits of Bash Script v. Python Script for Shell-Command-Heavy Utility

I need to write a script to do the following: Monitor a queuing system, which is accessible by shell commands. Create directories from templates using a mix of inline text editing, cp/mv, command line scripts, and compiled c++ programs. Check for error conditions. Write files on error conditions. Note: 2D arrays would be mildly usefu...

How do I find the top-level parent PID of a given process using bash?

Let's say I run ps axf and I can see that my command's process tree looks like this: 800 ? Ss 0:00 /usr/sbin/sshd 10186 ? Ss 0:00 \_ sshd: yukondude [priv] 10251 ? S 0:00 \_ sshd: yukondude@pts/0 10252 pts/0 Ss 0:00 \_ -bash 10778 pts/0 S 0:00 \_ su - 10785 p...