Questions for bash


How to write a bash script to set global environment variable?

Recently I wrote a script which sets an environment variable, take a look:

How to get the percent of packets received from Ping in bash?

When pinging a host I want my output just to show the percentage of packets (5 sent) received. I assume I need to use grep somehow but I can't figure out how (I'm new to bash programming). Here is ...

Linux scripting: hiding user input on terminal

I have bash script like the following:

Why does this sed command not match whitespace?

This bash script is supposed to remove leading whitespace from grep results:

loop over directory and file bash script - awk does not write to file

I would like to traverse through some directories that contain xml files. To each file I would like to apply an awk command and write the output to the file again. The file that is written is empty,

What's the best way to check that environment variables are set in Unix shellscript

I've got a few Unix shell scripts where I need to check that certain environment variables are set before I start doing stuff, so I do this sort of thing:

In Mac's terminal, can we have the command line arguments that are 'options' to the end of command?

Sorry if the title is bewildering. Let me illustrate by an example.

Scripting language choice for initial performance

I have a small lightweight application that is used as part of a larger solution. Currently it is written in C but I am looking to rewrite it using a cross-platform scripting language. The solution...

Check if a makefile exists before including it

I have a makefile that includes a Rules.mak file that holds includes to tools I want to use. Problem is that the tools folder has free options if they want to extract a version or use the "native"

POSIX “sort -n” alpha characters between zero and 1?

I'm having trouble getting POSIX "sort" to behave the way I want it to. When sorting numeric file names, those that start with letters show up between 0 and 1.

Script is re-reading arguments

When I supply the script with the argument: hi[123].txt it will do exactly what I want.

printf “columns” and newline

In my program I'm trying to set up column headers for a file that I will be adding to throughout the script.

Match all files under all nested directories with shell globbing

Is there a way to use shell Globbing to identify nested directories?

Simple Bash - for f in *

Consider this simple loop:

Regex remove comments but not shebang

I got a regex that removes the comments in bash using this regex code

Git Pre-Commit Hook - No such file or directory

I am getting an error when running a pre-commit hook in git, that I can't figure out. This is the script and the error is below.

Using ps2pdf correctly in a script?

I have a script below and I am having problems. I have several folders with PostScript file in them I want to batch convert to PDFs. I have done very little scripting in linux before but I think th...

How to make ssh to kill remote process when I interrupt ssh itself?

In a bash script I execute a command on a remote machine through ssh. If user breaks the script by pressing Ctrl+C it only stops the script - not even ssh client. Moreover even if I kill ssh client...

ANDing exit codes in bash

I have a bash script that runs three checks over my source code, and then exit 0 if all the commands succeeded, or exit 1 if any of them failed:

Bash console tab-completion in Ubuntu

I used to develop in RedHat and never had the following problem until I switched to Ubuntu:

Bash: Getting input from a manifest

Is it possible too have a manifest file with directory strings, fx.

Find for a class file in Linux that is present in JAR

I am trying to find a JAR file which contains my class using below command given in this link : Find a jar file given the class name?

Bash - Need to use exit but then call another function?

I'm writing a little script to use the webcam on the laptop and then email across the photo to me. The ffmpeg usage has to have a exit code for it to work so with this exit the mail function will n...

Keeping track of history of commands of multiple sessions of ksh

I am using multiple sessions of ksh on a linux machine. On one terminal when I do history, I only see history of commands typed on that terminal.

Fastest way to compare directory state, or hashing for fun and profit

We have a PHP application, and were thinking it might be advantageous to have the application know if there was a change in its makeup since the last execution. Mainly due to managing caches and su...

How to make sure a script only runs after another script

I have two python scripts running as cronjobs.

How do I pass variable inside find and bash -c?

Hey guys, I'm having issues with passing variable to %exe part of the code. Need your help.


I wort a bash script it looks like this:

Bash: wait for process to exit while tailing log file

In a bash script, I'm waiting on a child process's pid using wait. That child process is writing to a log file. Is there a way in the bash script to tail that log file to std out while at the same...

How do I pass an absolute path to the adb command via git bash for windows?

I'm trying to pass a unix style path to the Android adb command using a git bash (msysgit) but the shell is interpreting my path incorrectly. This is what I've tried so far:

While loop, how to read from second line of text file

i've tried everything for the past 2 hours to get this working but my experience in shell and programming is limited.

BASH script - execute command with variable and store result

I don't know how execute a command with variable and get result of this.

Making an alias for SSH MySQL login using ENDSSH heredoc

I want to make an alias that is kept in my bashrc file to log into a remote MySQL db via SSH.

Syntax error near unexpected token “elif” in bash

Here's my code to display some dialogs.

Bash variable scope

I want to search a repository file to see if I have a file in my directory. To do this, I loop the directory hopefully containing the file I am looking for, and I check to see if that file is in my

Unable to delete Linux user using PHP and bash script

I'm able to delete linux users directly from the shell using the command ./

if statement not evaluating correctly bash

I am testing if a variable is greater than another variable. The if evaluation is getting the same value no matter what the values are.

Assigning output of zenity to a variable

I have a script that makes a GUI list here:

How can I append the name of a file to end of each line in that file?

I need to do the following for hundreds of files:

Bash: Is it possible to change command before execution

I want to change the command so that command line flag(options) are placed before command line arguments, as which is done automatically by GNU getopt.

why bash -l -c “CMD” makes ruby find my gem?

In my ruby script,I required the gmail gem:

BASH: Using cut on space delimited file: Treating two spaces as one

I need to convert file full of lines like this:

Python or Bash commands to determine time since a cron job string would have triggered

I'm writing a Django app (although parts can be Bash) that stores the cron job strings of many other machines. It needs to calculate the amount of time since that cron job would have triggered on ...

Find duplicate records in large text file

I'm on a linux machine (Redhat) and I have an 11GB text file. Each line in the text file contains data for a single record and the first n characters of the line contains a unique identifier for the

How to I export a system scope environment variable in bash

I need to set a system environment variable from a bash script that would be available outside of the current scope. So you would normally export environment variables like this:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.