bash

Show Hexadecimal Numbers Of a File

I want to build a bash program that can read a file, like a *.bin and print all its hexadecimal numbers, as 'hex' editors do. Where I can start? ...

Do a complete flux of work on bash script

Hey there ! I'm trying to automate a proces which I have to do over and over again in which I have to parse the output from a shell function, look for 5 different things, and then put them on a file I know I can match patterns with grep however I don't know how to store the result on a variable so I can use it after :( I also have to p...

How to execute a bash command stored as a string with quotes and asterisk

I try to execute the following command : mysql AMORE -u username -ppassword -h localhost -e "SELECT host FROM amoreconfig" I store it in a string : cmd="mysql AMORE -u username -ppassword -h localhost -e\"SELECT host FROM amoreconfig\"" Test it : echo $cmd mysql AMORE -u username -ppassword -h localhost -e"SELECT host FROM am...

Executing python script in background in init.d

to interact with my iPhone, i have created a python script that sends and recives data through a socket, the script must be started after emule in order to work, i have thought of something like this: PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DAEMON=/usr/local/bin/amuled WEB=/usr/local/bin/amuleweb NAME=amuled DE...

[SHELL SCRIPT] echo removing backslash characters

Hi, I am trying to write a script which parses the fields in the program and prints them to standard output. Input file data is like this field1 field2 Fields are separated by tabs Initially, I tried to write it in AWK. cat test.txt | while read line; do entity=`awk -F "\t" '{print $2}'`;echo $entity; done This works fine on comm...

Unexpected operator error

What is wrong in my code? #!/bin/sh LOOK_FOR="$1" for i in `find $2 -name "*jar"`; do echo "Looking in $i ..." #jar tvf $i | grep $LOOK_FOR > /dev/null jar tvf "$i" | grep "$LOOK_FOR" if [ $? == 0 ] ; then echo "==> Found \"$LOOK_FOR\" in $i" fi done #line 13 Output wk@wk-laptop:$ sh lookjar.sh org/apache/axis/mes...

Mutable list or array structure in Bash? How can I easily append to it?

I'm trying to collect string values in a bash script. What's the simplest way that I can append string values to a list or array structure such that I can echo them out at the end? ...

one line assignment in bash

i have a whole bunch of tests on variables in a bash (3.00) shell script where if the variable is not set, then it assigns a default, e.g.: if [ -z "${VARIABLE}" ]; then FOO='default' else FOO=${VARIABLE} fi I seem to recall there's some syntax to doing this in one line, something resembling a ternary operator, e.g.: FOO=${...

From Shell: Delete all files with apostrophes

How do I delete all files in a folder that has an apostrophe? for example: Baird/'s Tunnel.jpg Bach/'s Birds.jpg This isn//'t good.png I would like all those files deleted but anything that doesn't have an apostrophe to remain intact, like: this is good.jpg donotdelete.png ...

Bash: Recursively remove files

Does anyone have a solution to remove those pesky ._ and .DS_Store files that one gets after moving files from a Mac to A Linux Server? specify a start directory and let it go? like /var/www/html/ down... ...

Easy Way to Split a Large Text File?

I've got a large (by number of lines) plain text file that I'd like to split into smaller files, also by number of lines. So if my file has around 2M lines, I'd like to split it up into 10 files that contain 200k lines, or 100 files that contain 20k lines (plus one file with the remainder; being evenly divisible doesn't matter). I coul...

How to get a flat XML so that external entities are merged to the top level

I know this is a borderline case whether it really belongs to stackoverflow or superuser, but as it seems there are quite a few 'editing code' questions over here, I am posting it on SO. I have a pile of XML files that someone in their infinite wisdom have decided to explode to a multiple files using the tags, which in result makes deb...

using find with exec

Hi I want to copy files found by find (with exec cp option) but, i'd like to change name of those files - e.g find ... -exec cp '{}' test_path/"test_"'{}' , which to my test_path should copy all files found by find but with prefix 'test'. but it ain't work. I'd be glad if anyone could give me some ideas how to do it. best regards ...

How to extract substring from a text file in bash?

I have lots of strings in a text file, like this: "/home/mossen/Desktop/jeff's project/Results/FCCY.png" "/tmp/accept/FLWS14UU.png" "/home/tten/Desktop/.wordi/STSMLC.png" I want to get only the file names from the string as I read the text file line by line, using a bash shell script. The file name will always end in .png and will al...

Why does set -e cause my script to exit when it encounters the following?

Hi All, I have a bash script that checks some log files created by a cron job that have time stamps in the filename (down to the second). It uses the following code: CRON_LOG=$(ls -1 $LOGS_DIR/fetch_cron_{true,false}_$CRON_DATE*.log 2> /dev/null | sed 's/^[^0-9][^0-9]*\([0-9][0-9]*\).*/\1 &/' | sort -n | cut -d ' ' -f2- | tail -1 ) if ...

What is '$$' in the bash shell?

I'm beginner at bash shell programming. Can you tell me about '$$' symbols in the bash shell? If I try the following #> echo $$ it prints #>18756 Can you tell me what this symbol is used for and when? ...

How can I write a Bash Script to display a menu, accept user input and display data?

I want to write Bash Script with User Input for my assignment called "book store service". Firstly, it has option menu like "add new book name " "author name" "remove book" "update" "search" "show book list" "Exit". If I choice option 1, I've got to input new book's name. How could I write the user input and display output data when I ch...

Shell variable expansion - indirection problem while calling a utility with env

Hi all, sorry if this is a repeated question but I was trying to figure out env, ( i.e. calling a util with a new environment). Just as an example my environment variable KDEDIRS = /usr in my current environment and lets say I type: env -i KDEDIRS=/home/newkdedir env This outputs KDEDIRS=/home/newkdedir as expected. (i.e calling se...

Why time command in linux has different output when I type it in shell than I use it in script?

Hey, The problem is when I use time in shell I get output like that: 1.350u 0.038s 0:01.45 95.1% 0+0k 0+72io 1pf+0w And when Im using it in script I get: real 0m1.253s user 0m1.143s sys 0m0.047s I mean why? And in shell script at the beginning I write: #!/bin/bash ...

Python's subprocess.Popen() and source

A third-party Python 2.5 script I'm trying to debug has got me stymied. The relevant part of the script is: proc = subprocess.Popen( "ls && source houdini_setup", shell = True, executable = "/bin/bash", ) There is a daemon that listens to port 5001 and runs the above s...