bash

count number of files generated from split command

I want to work on the files generated by the split command. How do I count these files? I am moving these to a separate directory, so it would help if someone could tell me how to store the output of ls -1|wc -l to a variable in a shell script. ...

stdout to variable. with mktmp, sed, grep, etc. line by line

Hi, I use ldapsearch to get some users from my LDAP-Server. The command replies something like this: uid: name.surname homeDirectory: /home/name sambaSID: S-1-4-32-224545876-87201423761-4821562975-6853 sambaHomeDrive: G: description: poI description: pPI sn: naut givenName: givenName: peter mail: [email protected] Now I want to assi...

How to create argument tokens (C++ in Unix)

Hello, all. I am trying to write a microshell in C++ to run in BASH. I am using getline() to read a command and its arguments as input by the user into a holding array. I use strtok() to parse the command array and return the first item (the actual command the the user wants to run) and want to use execlp() to run said command. My pr...

how to check if a string has spaces in bash shell

say a string might be like "a b '' c '' d", how can I check that there is single/double quote and space contained in the string? ...

Synchronize shell script execution

A modified version of a shell script converts an audio file from FLAC to MP3 format. The computer has a quad-core CPU. The script is run using: ./flac2mp3.sh $(find flac -type f) This converts the FLAC files in the flac directory (no spaces in file names) to MP3 files in the mp3 directory (at the same level as flac). If the destinatio...

Retrieving the First Non-Option Command Line Argument

I am trying to write a wrapper shell script that caches information every time a command is called. It only needs to store the first non-option argument. For example, in $ mycommand -o option1 -f another --spec more arg1 arg2 I want to retrieve "arg1." How can this be done in bash? ...

BASH: Does it support conditional variables like var="test"?"1":"2"

I am new to bash but have done lots of PHP, and Javascript. Is there some sort of equivilent to this PHP? $default = 10; $var = (!$var) ? $default : $var; Thanks ...

compile the entire bash shell into my app

Hi I want to know how i compile the entire bash shell into my app.I read somewhere that for this i compile its Subroutine. how? Thanks in advance ...

Nested case in bash script

I have written the following function in a bash script but it is not working. Am I missing something obvious? main_menu() { dialog \ --title "Sim Gateway Infomation Utility" \ --menu "What do you want to do?" 12 60 5 \ Summary "View overall summary" \ Details "View details of a sim bank" \ Modify "Modify used minutes...

Loop SQlite3 database continuously, when query found run script for first 3

I have a SQlite database gets populated when ever someone adds a filename and dir to it, then I want the script to read the newest 3 entries (done with the "LIMIT 3") then I want this script to take those 3 entries and start the "script1.sh" for each of them, then once the script1 has finished one of the 3, I want it to look back into th...

Used MacPorts to install WordPress. Where is it now?

Hi, I used MacPorts shell to download and install WordPress: port install wordpress It went just fine: ---> Computing dependencies for libxml2 ---> Fetching libxml2 ---> Attempting to fetch libxml2-2.7.5.tar.gz from http://arn.se.distfiles.macports.org/libxml2 ---> Verifying checksum(s) for libxml2 ---> Extracting libxml2 --->...

Wildcard expansion - searching for one in a set of possibilities

Hi all, I could have sworn you could do the following: ls *.{java, cpp} but that does not seem to work. I know this answer is probably on the site somewhere but I couldn't find it via search. For instance, if I want to be able to use the globbing with a find command, I would want to do something like find . -name "*.{java,cpp}" | ...

Java in bash at university fails with NoClassDefFoundError

I know there are many posts concerning NoClassDefFoundError, they all seem to be talking about jar files. While I'm comfortable with java in eclipse, I'm pretty lost as to why the simplest thing I can come up with is not functioning, unless they broke something on the university side of this. public class hello { public static void ...

Need to write a program to sanely configure a login shell

I just started using a Solaris 10 (Sparc) box where I telnet in and get confronted with a very unfriendly interface (compared to the standard bash shell I use in cygwin or linux) --- the arrow keys do not work as I expect them to. Being an NIS system, changing the shell is not as easy as using the "chsh" command. And setting the SHELL ...

GUI shell script editor with function overview

Is there an editor for Unix shell scripts such as Bash that has a kind of function overview as most Eclipse editors? I have a really large shell script with a lot of functions here and I want to move quickly from one function to next. Or is there any other way to get such an overview? ...

shell script to compare files and print formatted output

I'm trying to write a shell script which will compare two files, and if there are no differences between then, it will indicate that there was a success, and if there are differences, it will indicate that there was a failure, and print the results. Here's what I have so far: result = $(diff -u file1 file2) if [ $result = "" ]; then ...

Joining Line Breaks With Condition in SED

I have data that looks like this: > sq1 foofoofoobar foofoofoo > sq2 quxquxquxbar quxquxquxbar quxx > sq3 foofoofoobar foofoofoo > sq4 foofoofoobar foofoo I want to join the lines on the basis of ">sqi" header as cut-off line, i.e. yielding: foofoofoobarfoofoofoo quxquxquxbarquxquxquxbarquxx foofoofoobarfoofoofoo foofoofoobarfoofoo ...

Exclude .svn directories from grep

When I grep my Subversion working copy directory, the results include a lot of files from the .svn directories. Is it possible to recursively grep a directory, but exclude all results from .svn directories? ...

How to write a bash script that cuts images into pieces using image magick?

Hi, I have a number of input images that contain multile smaller images, all in a single row. All the contained images are the same size. So, for example, the image input.png may be 480x48 and contain 10 48x48 images, all in one row. Using the imagemagick convert tool (or any other tool supplied with the defaul imagemagick suite), I wa...

Calling external commands with git aliases

I want to restart my virtual server after switching branches, and tried adding some aliases in my .gitconfig but did not get it to work. co = checkout | !rap only runs rap, the restart script. co = checkout && !rap and some other things I tried (like checkout $1) gives my "git usage: bla bla". ...