bash

Passing parameter through Shell to C

name="Rahul Kapgate arg" temp=$name ./a.out -a "$temp" This will give me a following output :: Rahul Kapgate arg Instead of ./a.out -a "$temp" if i put following logic then it is generating differant output. cmd="./a.out -a \"$temp\"" $cmd Output :: "Rahul [ a.out is nothing but the printing the 1st parameter through C unsing opta...

git: check if pull needed

How to check whether the remote repo has changed and I need to pull? Now I use this simple script: git pull --dry-run | grep -q -v 'Already up-to-date.' && changed=1 but it is rather heavy. Do you know any better way? The ideal solution would check all the remote branches, and return names of the changed branches and the number of n...

vmstat and column

I want to use column utility to format output of iostat in aligned columns. I want to run something like: vmstat 1 10 | column -t But the output appers only after 10 sec (vmstat completes its work) and not each second. Any ideas? ...

Preserving quotes in bash function parameters

What I'd like to do is take, as an input to a function, a line that may include quotes (single or double) and echo that line exactly as it was provided to the function. For instance: function doit { printf "%s " ${@} eval "${@}" printf " # [%3d]\n" ${?} } Which, given the following input doit VAR=42 doit echo 'single quote ...

Start serval applications and pipe it to current terminal

How can I start serval applications in one script and pipe the output to current terminal? For development I need a script which starts three webservers (on three ports, of course) and pipe the output of these to current terminal. The difficult is to stop these webservers at the end of shell. I have to send a signal or better send [Ctr...

how to interact with an external script(program)

there is a script that expects keyboard input, i can call that script with os.system('./script') in python, how is it possible to send back an input to the script from another calling script? update: the script is: $ cat script #!/usr/bin/python for i in range(4): name=raw_input('enter your name') print 'Welcome %s :...

BASH: Split MAC Address -> 000E0C7F6676 to 00:0E:0C:7F:66:76

Hy, Can someone help me with splitting mac addresses from a log file? :-) This: 000E0C7F6676 should be: 00:0E:0C:7F:66:76 Atm i split this with OpenOffice but with over 200 MAC Address' this is very boring and slow... It would be nice if the solution is in bash. :-) Thanks in advance. ...

bash string equality

In bash, what's the difference, if any, between the equal and double equal test operators? [[ "a" = "a" ]] && echo equal || echo not-equal [[ "a" == "a" ]] && echo equal || echo not-equal [[ "a" = "b" ]] && echo equal || echo not-equal [[ "a" == "b" ]] && echo equal || echo not-equal results in: equal equal not-equal not-equal ...

How to change case of UTF file.

Hello I have UTF file in uppercase and I want to change all words to lowercase. I have tried: `$ tr '[:upper:]' '[:lower:]' < input.txt > output.txt` but that changes only cheracter without accent. Thanks ...

Bash script to read a file

Not sure why the last line does not cut the " from the script: #!/bin/bash FILENAME=$1 while read line do cut -d '"' -f2 echo $line done < $FILENAME $ cat file "1" test "2" test "3" test "4" test "5" test If I run this script with the following command: $ ./test file 2 3 4 5 "1" test ...

Bash script to mkdir

I am trying to create a directory based on a variable entered by a user and then save files there. I thought this would be simple enough for me but I get an error message "No such file or directory" when I try to save there. When I hit "ls" it lists the directory with a "?" after it. I am working with an .sh script on a Mac terminal....

How can I capture the PID and output of a backgrounded PHP process at the same time?

I have one PHP script that has to start a second script in the background using exec. The parent script needs to capture the PID of this new process, but I also need to capture any potential output of the child script so it can be logged in the database. I can't just have the child script log to the database because I also need to captur...

creating a bash script - loop through files

I was wondering, I need to run indent with a bunch of parameters as: indent slithy_toves.c -cp33 -di16 -fc1 -fca -hnl -i4 -o slithy_toves.c What I want is to read each *.c and *.h files and overwrite them with the same name. How could I do this in a bash script, so next time I can run the script and do all the indentation at once? ...

loop over directories to echo its content

The directories are variables set to the full-path for e in "$DIR_0" "$DIR_1" "$DIR_2" do for i in $e/* do echo $i done The output for each line is the full path. I want only the name of each file ...

BASH: how to perform arithmetic on numbers in a pipe.

I am getting a stream of numbers in a pipe, and would like to perform some operations before passing them on to the next section, but I'm a little lost about how I would go about it without breaking the pipe. for example > echo "1 2 3 4 5" | some command | cat 1 4 9 16 25 > Would you have any ideas on how to make something like this...

sudo in andLinux allows root access without password

Hi! While working under andLinux on a bash script that has to sudo some stuff, I arrived at the following line.. this line seems to provide root access but doesn't require a valid password: echo | sudo -S cat /etc/shadow >/dev/tty Can anyone explain why this happens? Without the 'echo |' or the '>/dev/tty' this doesn't work and reques...

Forcing a python script to take input from STDIN

A python script I need to run takes input only from a file passed as a command line argument, like so: $ markdown.py input_file Is there any way to get it to accept input from STDIN instead? I want to be able to do this through Bash, without significantly modifying the python script: $ echo "Some text here" | markdown.py If I have ...

inserting text into a specific line

I've got a text file, and using Bash I wish to insert text into into a specific line. Text to be inserted for example is "!comment: http://www.test.com" into line 5 !aaaa !bbbb !cccc !dddd !eeee !ffff becomes, !aaaa !bbbb !cccc !dddd !comment: http://www.test.com !eeee !ffff ...

Reload .profile in bash shell script (in unix)?

Hi all, I'm new to bash shell scripting, and have come across a challenge. I know I can reload my ".profile" file by just doing: . .profile but I'm trying to the same in a bash script I'm writing and it is just not working. Any ideas? Anything else I can provide to clarify? Thanks ...

LD_PRELOAD affects new child even after unsetenv("LD_PRELOAD")

my code is as follows: preload.c, with the following content: #include <stdio.h> #include <stdlib.h> int __attribute__((constructor)) main_init(void) { printf("Unsetting LD_PRELOAD: %x\n",unsetenv("LD_PRELOAD")); FILE *fp = popen("ls", "r"); pclose(fp); } then in the shell (do the 2nd command with care!!): gcc prel...