shell

Advice on which language to use

I'm trying to create a web application which will get input from system. What this application should do is to listen what happens when some shell scripts are executing and reporting the status trough web. An example : I'm copying thousands of records with shell script, and while this is still executing I'd like pass the current stat...

bash/fish command to print absolute path to a file

Question: is there a simple sh/bash/zsh/fish/... command to print the absolute path of whichever file I feed it? Usage case: I'm in directory /a/b and I'd like to print the full path to file c on the command-line so that I can easily paste it into another program: /a/b/c. Simple, yet a little program to do this could probably save me 5 ...

Ignoring the forward slash in a shell script

Hello wonderful computing persons, This is really simple and I hope I'm not being redundant. I'm writing a shell script with this command: sed -e 's/OLD_ITEM/NEW_ITEM/g' but I actually want to do something that includes a directory: sed -e 's/FOLDER/OLD_ITEM/NEW_ITEM/g' how do ignore the forward slash so that the entire line FO...

Run a shell script on all files within a directory and its sub-directories

Good evening fellow computational authors, I'm trying to run the following script: find . -name '*.php' -exec /search_replace.sh {} \; so that it runs search_replace.sh on all the .php files in a folder and its sub-folders. I keep on getting the error: find: /search_replace.sh: No such file or directory Any assistance? ...

Advantages and disadvantages between zsh and emacs' (e)shell

i have currently switched over to emacs (aquamacs) and am in the process of migrating my entire workflow into it one step at a time (org-mode, dired, etc., from pathfinder, notational velocity, etc.). the one thing i have yet to try (and seems to be the biggest obstacle thus far) is the built-in emacs shell (shell and/or eshell, here on...

Dumping text files

I'm writing a shell script that will create a textual (i.e. diffable) dump of an archive. I'd like to detect whether or not each file is printable in some given character set, and if it is printable, I'd like to convert to that character set from whatever one it's in, if this is possible, and make its contents part of the dump. I've co...

C - pseudo shell and concurrency

I'm writing a pseudo shell program which creates a child from a parent process. The parent process waits for the child to finish before continuing. My forking code looks something like this: if(fork()==0) { execvp(cmd, args); } else { int status = 0; wait(&status); printf("Child exited with status of %d\n", status); ...

Generating sequential number lists in tcsh

Hi, I've been trying to find a workaround to defining lists of sequential numbers extensively in tcsh, ie. instead of doing: i = ( 1 2 3 4 5 6 8 9 10 ) I would like to do something like this (knowing it doesn't work) i = ( 1..10 ) This would be specially usefull in foreach loops (I know I can use while, just trying to look for an a...

Linux shell passing variable values to main programme

I have a programme, ./a that I run in a loop in shell. for((i=1 ; i<=30; i++)); do ./a arg1 5+i &//arg2 that I need to pass in which is the addition with the loop variables done How could I passed in the arg2 which is the addition with loop variables? Also, I has another programme which is ./b which I need to run once and takes in a...

Pipeline metacharacter in variable in bash

In my bash script I need to check if logger binary exists. If so, I pipe the application output to it. Edit-------- | It needs to be piping, the application should work permanently. --------------- I tried to put the pipeline stuff to a variable and use it later. Something like: if [ -e /usr/bin/logger ]; then OUT=| /usr/bin/logger ...

Using sed on a shell scripts on multiple files

Hello friendly computing people, This is a two part question. I'm writing two shell scripts with the goal of doing a 'find and replace' in all the index.php files in a folder and its subfolders. The first shell script is this: echo "running on all directories…" find . -name '*.php' -exec ./search_replace.sh {} \; which then runs th...

how the keyword “if” test the value true of false?

In bash script if [ 1 ] then echo "Yes" else echo "No" fi Output: Yes It represent that '1' is treated as true value. But in code: word = Linux letter= nuxi if echo "$word" | grep -q "$letter" then echo "Yes" else echo "No" fi Output:No But echo "$word" | grep -q "$letter" will return 1, why the result is N...

How do you extract only the contents of an ELF section.

I've tried the following, but the resulting file is still an ELF and not purely the section content. $ objcopy --only-section=<name> <infile> <outfile> I just want the contents of the section. Is there any utility that can do this? Any ideas? ...

Determine function and file dependency of a shell script?

I'm looking for a way of processing a shell script to determine: which commands, scripts or functions are called in the script. which files are accessed by the script (r or w) . It doesn't need to recurse down through the dependencies, just list what it runs directly. I could probably write something that does this myself but it must...

C - passing an unknown command into execvp()

I'm writing a fake shell, where I create a child process and then call execvp(). In the normal shell, when I enter an unknown command such as 'hello' it returns 'hello: Command not found.' However, when I pass hello into execvp(), it doesn't return any error by default and just continues running the rest of my program like nothing happen...

Remove file in a tar, with wildcard and exception

I have a tarball, and i want to remove all .tcl, .bat , .log files except pkgIndex.tcl in it. if i do tar --delete -f mytarball.tar --wildcards *{.tcl,.log,.bat} my pkgIndex.tcl will be deleted, how to put that as exception in my pattern wildcard? Just tried tar --delete -f mytarball.tar --wildcards *{.tcl,.log} --exclude=*pkgIn...

Is it possible to set variables equal to expressions in UNIX?

In Unix, how would one do this? #!/bin/sh x=echo "Hello" | grep '^[A-Z]' I want x to take the value "Hello", but this script does not seem to work. What would be the proper way of spelling something like the above out? ...

Implementing Pipes in a C shell (Unix)

Basically I have created a shell using standard POSIX commands, I want to be able to Implement Piping as well. Right now it handles commands correctly, and can do background processing with &. But I need to be able to pipe using | and >> as well. For example something like this: cat file1 file2 >> file3 cat file1 file2 | more more file1 ...

Using exec and pipe in ant

Hello, I'm trying to run the following command using exec in ant: ls -l /foo/bar | wc -l Currently, I have my exec looking like this: <exec executable="ls" outputproperty="noOfFiles"> <arg value="-l" /> <arg value="/foo/bar" /> <arg value="|" /> <arg value="wc" /> <arg value...

How to replace catch block in *.java using sed ?

How to replace the following pattern in a java project catch(SQLException e) { \\TO DO } with catch(SQLException e) { S.O.P(); } Please note that the file will have other patterns like catch(IOException e) { // To Do } which should not be changed. I tried sed 's/catch\(SQLException[^\}]*}/catch(SQLException e)...