shell

wget errors breaks shell script - how to prevent that?

I have a huge file with lots of links to files of various types to download. Each line is one download command like: wget 'URL1' wget 'URL2' ... and there are thousands of those. Unfortunately some URLs look really ugly, like for example: http://www.cepa.org.gh/archives/research-working-papers/WTO4%20(1)-charles.doc It opens OK in a...

ASSIGN win XP commandline output to variable

i would like to translate a following script from linux shell to Windows XP shell GPSID=$(awk '/GPSID/ {print $3}' gora.RTK ) awk -v variable=${GPSID} 'BEGIN {printf "Numer seryjny : " variable,$1}' >>out.txt The second line has been translated; the problem is with defining a variable that contains shell output in windows :-( ...

How do I recursively list all directories at a location, breadth-first?

Breadth-first list is important, here. Also, limiting the depth searched would be nice. $ find . -type d /foo /foo/subfoo /foo/subfoo/subsub /foo/subfoo/subsub/subsubsub /bar /bar/subbar $ find . -type d -depth /foo/subfoo/subsub/subsubsub /foo/subfoo/subsub /foo/subfoo /foo /bar/subbar /bar $ < what goes here? > /foo /bar /foo/subfoo...

Bash - Passing arguments by reference

Hi all, I want to ask if it is possible to pass arguments to a script function by reference: i.e. to do something that would look like this in C: Void boo (int & myint) { myint= 5; } main (){ int t= 4; printf t; // t->4 boo (t); printf t; // t ->5 } So then in BASH I want to do somthing like: Function boo () { ...

what is the optimal way to assemble a file?

I've large number of small files with sequential filenames & i want to create a single file out of it. What is the fastest way to do this? e.g. 1.tgz.1 1.tgz.2 1.tgz.3 =========> 1.tgz ...

Who calls this function?

At my last job (legacy FORTRAN 77 code), we had files of cross references that list what subroutines called other subroutines, in what files subroutines were defined, what common blocks held what variables, what subroutines included what common blocks, etc. These were then used by shell scripts that grepped the cross reference files and...

How do you start Unix screen command with a command?

According to the docs for the Unix "screen" command, you can configure it in .screenrc to start with a bunch of default screens, each running a command that you specify. Here's my cofig: # Default screens screen -t "shell_0" 1 screen -t "autotest" 2 cd ~/project/contactdb ; autotest It will not run the autotest command. That window ...

-mtime FIles older than 1 hour

Hello all, I have this command that I run every 24 hours currently. find /var/www/html/audio -daystart -maxdepth 1 -mtime +1 -type f -name "*.mp3" -exec rm -f {} \; I would like to run it every 1 hour and delete files that are older than 1 hour. Is this correct: find /var/www/html/audio -daystart -maxdepth 1 -mtime +0.04 -type f -...

Iterating over two lists in parallel in /bin/sh

I have two lists of equal length, with no spaces in the individual items: list1="a b c" list2="1 2 3" I want to iterate over these two lists in parallel, pairing a with 1, b with 2, etc.: a 1 b 2 c 3 I'm attempting to support modern portable Bourne shell, so Bash/ksh arrays aren't available. Shelling out to awk would be acceptable ...

Startup script on EC2

I've created a custom Amazon AMI (Fedora) runs a few scripts and then shuts down. The problem with AMI's is that if my code changes there has to be a way for the AMI instance to get the latest scripts before it executes them. I wrote a shell script & put it in /etc/init.d/nt_startup To keep the code up to date, I execute a "git pull...

What directory is '~' when I type 'cd ~' ?

I'm only new to using SSH, but when I log in I end up in the directory ~, which in general is the same directory when FTPing in. I can still go to /, but I don't know what the ~ means. Home? Where is it in relation to /, or how could I find out? ...

Control-r reverse-i-search in Cygwin bash: how do you "reset" the search?

Question: How do you tell ctrl-r reverse-i-search to "reset itself" and start searching from the bottom of your history every time? Background: When using reverse-i-search in bash, I always get stuck once it is finished searching up through the history and it cannot find any more matches. Sometimes I hit escape and re-invoke ctrl-R a se...

Command-line dialog tool for Windows

I need a dialog tool similar to cdialog (or whiptail), but one that will work on Windows. I have MinGW and compiling something from source is no problem, but both cdialog and whiptail, the only ones that I know of, contain code that is UNIX-specific, and so they will not compile on Windows. Are there any alternatives that I can use? I...

Is there anything like IPython / IRB for Perl?

I've grown accustomed to using IPython to try things out whilst learning Python, and now I have to learn Perl for a new job. Is there anything out there like IPython for Perl? In particular, I'm interested in completion and access to help. ...

Bash script does not continue to read the next line of file

Hello all, I have a shell script that saves the output of a command that is executed to a CSV file. It reads the command it has to execute from a shell script which is in this format: ffmpeg -i /home/test/videos/avi/418kb.avi /home/test/videos/done/418kb.flv ffmpeg -i /home/test/videos/avi/1253kb.avi /home/test/videos/done/1253kb.flv f...

"Bring to front" for Windows XP command shell

Is there a command I can put into a Windows XP .bat file to bring the command shell to the front? ...

Zsh: extract a CGI query to an associative array

I have a CGI query like this: 'a=1&b=2&c=3'. I want to extract it in an associative array A such as $A[a]=1, $A[b]=2 and $[c]=3. I found this way, but I would like to find a simpler (shorter) way to this : QUERY='a=1&b=2&c=3' typeset -a T T=( ${(s:&:)QUERY} ) typeset -A A A=() for v in $T; do A+=( ${(s:=:)v} ) done (bonus: find ...

Resize a list of images in line command

I would like to resize a list of images, all in the directory. To achieve that, I use convert from imagemagick. I would like to resize image1.jpg image2.jpg ... into image1-resized.jpg image2-resized.jpg ... I was wondering if there is a method to achieve this in a single command line. An elegant solution could be often useful, not...

Press alt + numeric in bash and you get (arg [numeric]) what is that?

This is one of those questions where it is easier to ask someone else instead of spending thirty minutes trying to "guess" for the correct place in the documentation or search engine terms: Press alt + numeric in bash and you get (arg [numeric]) what is that? ...

Inheriting aliases inside UNIX /usr/bin/script

The UNIX "/usr/bin/script" command will create a running transcript of your shell session (see "man script" for more info). However, when inside a script instance, it seems to forget the parent shell's env vars, aliases, etc. The following example demonstrates how the "ll" alias I define is ignored inside "script": zsh> mkdir temp zsh...