Showing posts with label bash. Show all posts
Showing posts with label bash. Show all posts

Monday, June 11, 2012

bash: defining a variable with or without export


What is export for? What is the difference between:




export name=value

generate a core dump in linux


I have a process in linux that's getting a segmentation fault. How can I tell it to generate a core dump when it fails?

Sunday, June 10, 2012

bash: redirect and append both stdout and stderr


To redirect stdout in bash, overwriting file




cmd > file.txt



To redirect stdout in bash, appending to file

Friday, June 8, 2012

How do I write stderr to a file while using "tee' with a pipe?


I have the below command line argument which will print the output of aaa.sh to the screen while also writing stdout to bbb.out; however I would also like to write stderr to a file ccc.out. Any suggestions on how to modify the below piece? Thanks!

Tuesday, June 5, 2012

Can a shell script set environment variables of the calling shell?


I'm trying to write a shell script that, when run, will set some environment variables that will stay set in the caller's shell.

bash - automatically capture output of last executed command into a variable


I'd like to be able to use the result of the last executed command in a subsequent command. For example,

Pipe to/from Clipboard


Is it possible to pipe to/from the clipboard in bash? Whether it's piping to/from a device handle or using an auxiliary application, I can't find anything.

BASH: Possible to abort shell script if any command returns a non-zero value?


I have a Bash shell script that invokes a number of commands. I would like to have the shell script automatically exit with a return value of 1 if any of the commands return a non-zero value.

Sunday, June 3, 2012

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?

Friday, June 1, 2012

unix shell script find out which directory the script file resides?


Basically I need to run the script with paths related to the shell script file location, how can I change the current directory to the same directory as where the script file resides?

Wednesday, May 30, 2012

Best way to kill all child processes


I basically want to kill a whole process tree. What is the best way to do this using any common scripting languages. I am looking for a simple solution.

Monday, May 21, 2012

In the bash script how do I know the script file name?


How can I determine the name of the bash script file inside the script itself?

How do I prompt for input in a Linux shell script?


I want to pause input in a shell script, and prompt the user for choices. The standard 'Yes, No, or Cancel' type question. How do I accomplish this at a typical bash prompt?

Sunday, May 20, 2012

How can I get `find` to ignore .svn directories?


I often use the find command to search through source code, delete files, whatever. Annoyingly, because Subversion stores duplicates of each file in its .svn/text-base/ directories my simple searches end up getting lots of duplicate results. For example, I want to recursively search for uint in multiple messages.h and messages.cpp files:

How do I iterate over a range of numbers in bash?


How do I iterate over a range of numbers in bash when the range is given by a variable?

Friday, May 18, 2012

How to count all the lines of code in a directory recursively?


We've got a PHP application and want to count all the lines of code under a specific directory and its subdirectories. We don't need to ignore comments, as we're just trying to get a rough idea.

Thursday, April 19, 2012

generate php classes in bash


i have this script:




#!/bin/bash

if [[ -z "$1" ]] ; then
echo "Class is required"
exit 1;
fi

if [[ -z "$2" ]] ; then
package="Default"
else
package=$2;
fi

echo "<?php
/**
* $1.class.php
*
* Vcard class file.
* @name Project
* @author Author
* @link http://www.domain.com
* @copyright Copyright © 2011
* @package $package
* @version 1.0
*/

/**
* The main $1 class
* @package $package
*/
class $1 {

/**
* Constructor setup.
*/
public function __construct() {
}

/**
* Destructor setup.
*/
public function __destruct() {
}
}
" > $1.class.php

php -l $1.class.php
echo "Done";