shell

Linux number of files in directory curiosity

Just out of curiosity, is there any method in Linux to know the number of files in a directory in O(1) (independently of the number of files) without having to list the directory first? I'm searching for an alternative to ls | wc -l. Thanks! ...

Replacing the Windows shell with a WPF app

Hi, I want to replace Windows 7 Shell (32 and 64 bit) with my WPF application which should work as a Shell. The goal is WPF application will launch my Kiosk application and provide few services. My questions are How do I replace the Windows 7 Shell by my WPF application ? Do I have to do something special in my WPF application code ...

shell script cut and sed help

I have 2 two files $cat file1.txt field1=value1 field2=value2 field3=value3 :: :: $cat file2.txt something.field1.some otherthing.field2.anything anything.field3.something I need to read file1.txt and check whether file2.txt for fieldN and replace with valueN so that the result will be something.value1.some otherthing...

How can I use Perl regexp characters when inside a bash script?

I would like a command line function that I can run on any file to change the include("myinc.inc"); PHP statement to include 'myfile.inc'; I have made a start by adding the following to my ~/.bashrc file: function makestandard() { perl -p -i -e 's/include\("([\w\.]+)"\)/include '$1'/g' $* } I source ~/.bashrc; and run the command ...

Multiple wordlists in csh script foreach loop

I have a Cshell script that I am modifying to have related input and output locations. the functionality all happens in a foreach loop like so: set INPUT_LOCATION_LIST = "loc1 loc2 loc3 loc4" foreach location ($INPUT_LOCATION_LIST) #***Do some stuff *** end I would like to have an output list with different values than the input list...

Terminal on the web browser?

Is there a way to put the terminal on the web browser instead, so I just fire up localhost:80 and then I'll have a terminal on it that I can use and whatever I execute it will execute on my local web server? And the outputs I want to be displayed on the web browser too, just like a normal Terminal. I'm using Ruby on Mac OS X/Ubuntu. ...

simple use of function in shell script

Hi! I am trying to use the simple fuinction below. But i get error sayin unary oprator expected and the output is always one. Can any1 help me correct it. #!/bin/bash checkit () { if [ $1 = "none" ] then  echo "none" else  echo "one" fi } checkit ...

Getting result of executed shell command fails/hangs

I try to execute shell commands, this does work as it should. Even the result comes back (as is see on LogCat). The problem ist the last line of the result. Every time a readLine() on the last line occurs (which shouldn't occur, temp should be null), the app hangs forever and doesn't come back from the readLine call. Maybe you find the ...

Unix shell script: Update timestamp on all sub-directories and sub-files, including those with spaces

Here's what I'm trying to achieve. I have a directory with over 4200 sub-files/sub-directories, all of which need to be set to a certain timestamp. This is a problem because many of them have whitespaces and other weird characters. First thing I tried: touch $(find .) Won't work because of the spaces. It will update the timestamps o...

ShellEx: Starting Excel minimized or hidden

Using the following code I can run Excel from within C#: System.Diagnostics.Process p = new System.Diagnostics.Process(); p.StartInfo.FileName = "cmd.exe"; p.Start(); Can I make Excel start hidden or minimized using any command line parameters? (Edit: Tried p.StartInfo.WindowStyle and it had no effect.) I need to start Excel without...

Problem with using open4 in Ruby.

I have a script I want to execute with open4. Here is the file: script #!/usr/bin/env ruby print "Enter your username: " username = gets puts "Here is your username: #{username}" print "Enter your password: " password = gets puts "Here is your password: #{password}" Then I fire up IRB and type: ruby-1.9.2-p0 > pid, stdin, stdout, s...

Using javascript to open a shell

Is there a reliable crossbrowser way to open up a shell using javascript (e.g. explorer.exe)? ...

Testing for color support in Linux shell scripts

This is the second time I've wanted to do this and again my google-fu has failed me. When in the course of running a shell script (in my case a bash script) is there a program/script that tests whether the current shell supports color? Alternatively is there a way to take the terminal type and easily determine if it supports color? Ei...

Would it be possible to replace CMD with something else?

I never studied OSes, so forgive me if this sounds basic or silly, but I'm curious about if one could replace the cmd prompt in Windows. I am NOT asking for programs that actually do this, as I've looked around and not really seen any. What I'm asking is 1) if it's actually possible to write an entirely new program that would behave li...

How do I obtain only digits from a string?

Suppose I have a string like this: blah=-Xms512m I want the output as 512. I know I can get it using grep on Linux like this: echo $blah | grep -o -e [0-9]\\+ But this doesn't work on Solaris. Any nice solutions so that it's compatible on both, Linux and Solaris? Or atleast on Solaris? ...

Running bash function in command of su

In my bash script I execute some commands as other user. I want to call a bash function in command of su I defined in my script before. my_function() { do_something } su username -c "my_function" The above script doesn't work, of course my_function is not defined inside su. I have only the idea to save the function into separate fi...

Incremetal backups of directories with a batch/shell script

I'm trying to create a script that will automatically backup a complete directory tree. I also want it to work for incremental backups. Basically, it wil work like this: If file is in both source and destination and they are different, source file will be copied If file is in both source and destination and they are the same, nothing w...

How to execute a shell script from C in Linux?

How can I execute a shell script from C in Linux? ...

Executing shell script with system() returns 256. What does that mean?

I've written a shell script to soft-restart HAProxy (reverse proxy). Executing the script from the shell works. But I want a daemon to execute the script. That doens't work. system() returns 256. I have no clue what that might mean. #!/bin/sh # save previous state mv /home/haproxy/haproxy.cfg /home/haproxy/haproxy.cfg.old mv /var/run/ha...

Recording command line input and output on linux with C

Basically I want to do a program almost like a keylogger. The thing is that I as network admin sometimes I don't remember what I did to a machine on certain case, or same times I make howto's and tutorials for linux. I want to record what have i done. So basically the idea of this program is: you type the name of the program, (I call it...