shell

Question about bash script: tar -cvf /dev/nst0 /home/user1 >> file1.log

Hi I need help to understand the following command. tar -cvf /dev/nst0 /home/user1 >> file1.log Thanks! ...

Perl's diamond operator: can it be done in bash?

Is there an idiomatic way to simulate Perl's diamond operator in bash? With the diamond operator, script.sh | ... reads stdin for its input and script.sh file1 file2 | ... reads file1 and file2 for its input. One other constraint is that I want to use the stdin in script.sh for something else other than input to my own script. Th...

How to do text DIFF using PHP?

What is the best way to do this for PHP? Is there any PHP function that can do this, considering the column content could be very large? If PHP function is not available, what shell utility can I call? thanks ...

How to check for tabulator in files?

I would like to check a number of files for the existence of tab characters (ASCII 0x09) in them. (To assert that my sources are tab-free before committing them to repository.) Preferably with standard tools. Of course, grep springs to mind, but apparently grep "\t" file.txt doesn't match...?!? I am aware the answer is probably painfu...

Test Anything Protocol in Shell scripts

Has anyone seen, tried to implement, or otherwise played with TAP in shell? We're looking to create unit tests across many languages (don't get me started on why this doesn't exist so far), and since we have so much Perl code, we'll be looking at TAP (among others, I imagine). I've found a TAP library for C, Perl, of course, has it bui...

Recursively List all directories and files

Hi I would like to recieve the following output - Suppose the directory structure on the file system is like this: -dir1 -dir2 -file1 -file2 -dir3 -file3 -file4 -dir4 -file5 -dir5 -dir6 -dir7 The output from the script must be like: Directories: /dir1 /dir1...

Shell status codes in make

I use a Makefile (with GNU make running under Linux) to automate my grunt work when refactoring a Python script. The script creates an output file, and I want to make sure that the output file remains unchanged in face of my refactorings. However, I found no way to get the status code of a command to affect a subsequent shell if command...

How to read and process binary (base-2) logical representations from file

I have a file containing 800 lines like: id binary-coded-info --------------------------- 4657 001001101 4789 110111111 etc. where each 0 or 1 stands for the presence of some feature. I want to read this file and do several bitwise logical operations on the binary-coded-info (the operations depend on user input and on in...

How do I apply a shell command to many files in nested (and poorly escaped) subdirectories?

Hi! I'm trying to do something like the following: for file in `find . *.foo` do somecommand $file done But the command isn't working because $file is very odd. Because my directory tree has crappy file names (including spaces), I need to escape the find command. But none of the obvious escapes seem to work: -ls gives me the spa...

Can I get the absolute path to the current script in Korn Shell?

Is it possible to find out the full path to the script that is currently executing in Korn shell? i.e. if my script is in /opt/scripts/myscript.ksh, can I programmatically inside that script discover '/opt/scripts/myscript.ksh'? Thanks, ...

Escape a string

I'm writing a shell script and I want to escape a string. Is there any way to convert this: I'm happy. You're sad. to I\'m happy.\nYou\'re sad. I'm pretty sure there's some combination of sed/awk that does this.... Thanks ...

Why did my use of the read command not do what I expected?

I did some havoc on my computer, when I played with the commands suggested by vezult [1]. I expected the one-liner to ask file-names to be removed. However, it immediately removed my files in a folder: > find ./ -type f | while read x; do rm "$x"; done I expected it to wait for my typing of stdin:s [2]. I cannot understand its action....

Add --color to all Unix commands

Is it possible to "alias" all commands to append --color? Or instead have it automatically activated for every program that supports it? ...

Using local settings through SSH

Is it possible to have an SSH session use all your local configuration files (.bash_profile, .vimrc, etc..) on login? That way you would have the same configuration for, say, editing files in vim in the remote session. ...

How can I escape characters in SQLite via bash shell?

I am trying to send a query to SQLite from the command line using bash. I need to escape both single quotes and double quotes, and escape them so that bash does not misinterpret them. Here is a typical query: select * from contacts where source = "Nancy's notes"; How can I send this query from the command line? The basic syntax is som...

Save last working directory on Bash logout

Is it possible to save the last working directory when you do an "exit" in bash. So, the next time you login, it will be at the directory you were at when you last logged out. ...

How to execute a Unix shell script from Windows

I've got an AIX script I would like to run from a .NET application. I'm not opposed to kicking off a Windows batch file if that gives me better options. Most of what I've seen on Google relates to using a tool such as rsh or Plink, or using ssh or telnet. I don't have access to rsh or Plink (although I do have PuTTY and could probably g...

Compute numerical values from a space separated text file, within a range of lines

I have a file with the following values: for 3 threads: Average time taken for API1 is: 19097.7 nanoseconds. Average time taken for API2 is: 19173.1 nanoseconds. Average time taken for API2 is: 19777.7 nanoseconds. Average time taken for API2 is: 19243.1 nanoseconds. Average time taken for API1 is: 19737.7 nanoseconds. Average time take...

Surprise! the shell suggests command line switches

I noticed that the bash shell can suggest command line switches for your command. Just type your command, a dash (-) and type tab. The shell will show you available switches. For example, try: andy@andyx:~$ java - and press tab - Surprise! The question is: How do I interface with this feature. I.e., if I write a program that is ...

Why does my command-line not run from cron?

I have a perl script (part of the XMLTV family of "grabbers", specifically tv_grab_oztivo). I can successfully run it like this: /sw/bin/perl /path/to/tv_grab_oztivo --output /path/to/tv.xml I use the full paths to everything to eliminate issues with the Working Directory. Permissions shouldn't be a problem. So, if I run it from the...