bash

Bash, curl, eval and whitespace

I'm writing a script to execute CURL commands for a given user input. The script has multiple helper function to create the list of parameters (arguments) that will eventually be passed to CURL. A stripped out example, is as follows : #!/bin/bash function create_arg_list { # THIS HTTP HEADER VALUE COMES FROM THE USER and MAY CONTAI...

Pass ALL Arguments from Bash Script to Another Command

What is the simplest way to grab all the given arguments for a bash script and pass them all into another command within the script? For example: Command Line: ./runProgram.sh [ARGS HERE] Script: #! /bin/bash cd bin/ java com.myserver.Program [ARGS HERE] ...

In bash, how could I add integers with leading zeroes and maintain a specified buffer.

For example, I want to count from 001 to 100. Meaning the zero buffer would start off with 2, 1, then eventually 0 when it reaches 100 or more. ex: 001 002 ... 010 011 ... 098 099 100 I could do this if the numbers had a predefined number of zeroes with printf "%02d" $i. But that's static and not dynamic and would not work in my exampl...

Bash equivalent to Python's string literal for utf string conversion.

I'm writing a bash script that needs to parse html that includes special characters such as @!'ó. Currently I have the entire script running and it ignores or trips on these queries because they're returned from the server as decimal unicode like this: '. I've figured out how to parse and convert to hexadecimal and load these into py...

creating a reference for script

I want to make the following kind of reference: "ls" command, for example, is universally available in most *nix environments. User can type in from anywhere to execute the scripts. So, I write script "x". I want to make sure that from wherever the user type in x, the actual script "x" is referenced. Thus, if I have script "x" stored...

unix sorting, with primary and secondary keys

Hi! I have the following problem: I would like to sort a file on more fields. A sample tab separated file is: a 1 1.0 b 2 0.1 c 3 0.3 a 4 0.001 c 5 0.5 a 6 0.01 b 7 0.01 a 8 0.35 b 9 2.3 c 10 0.1 c 11 1.0 b 12 3.1 a 13 2.1 And i would like to have it sorted alphabetically by field 1 (w...

How join 2 variable in shell script ?

INPUT=10 OUTPUT_IN=20 KEYWORD="IN" echo $OUTPUT_"$KEYWORD" It should display 20 Mainly I am looking to generate the variable name OUTPUT_IN How to resolve this? ...

What's the best way to write to linux system files using PHP

We need some scripts to generate config files for network services such as DHCP, DNS and Network based on user input. These require root access, but I don't know how to run the PHP application as root. It's run through a public web interface. ...

Continually output file content to console?

Quick question, hopefully... I'm building an application with a fairly extensive log file. I'd like the ability at any time to monitor what a specific instance of my application is doing. I could open and close the log file a bunch of times, but its kind of a pain. Optimally, as lines are written to the log file, they would be written to...

Do commands run from current direcotry in a shell script?

In a bash shell script. I tried these two versions: java -jar abc.jar& and CMD="java -jar abc.jar&" $CMD The first verison works, and the second version complains that abc.jar cannot be found. Why? ...

HOWTO: Detect bash from shell script

The scenario is that users are asked to source a script file: $ source envsetup.sh This script file may use bash only feature so we have detect the running shell is bash or not. For other shells that share common syntax with bash, for example, sh, zsh, ksh, I'd like to report a warning. What is the most reliable way to detect the cu...

How do I convert a bash shell script to a .bat file?

Hi, I have a bash shell script on my Mac, that I need to convert to a .bat file (at least, that's what I've been told) for users that are on PCs. I was wondering the best way to go about this, or if anyone knows of any good references. I don't seem to be asking Google the right question to point me in the right direction. Specificall...

Prompt user to select a directory with a bash script and read result.

Hi, I want to be read a dir with a bash script (actually I am using zsh). I want to list the current folders in the same dir and display it to the user asking them to enter a number to select the correct folder. Please select a Folder eg, 1,2,3. 1. Folder Name 1 (this should the acutal name of the folder in the dir 2. Folder 2 3. Fold...

image magick problem with java

to be specific in this i'm trying to run the next line on java: convert /home/mohamed.hegab/Desktop/1263392123111.jpg -gamma .45455 -resize 400x400 -gamma 2.2 -quality 92 /home/mohamed.hegab/Desktop/small.jpg which is run great on the bash command line but when i run it on the java using process builder it gives me strange result. ...

How to use a bash script variable with sed

I execute the following bash script: #!/bin/bash version=$1 echo $version sed 's/\${version.number}/$version/' template.txt > readme.txt I'm expecting to replace all instances of ${version.number} with the contents of the variable "version". Instead the literal text $version is being inserted. What do I need to do to make sed use the...

interpreting shell commands within Bash if/else statements

While trying to make a conditional statement to check the amount of files in a directory, I have stumbled upon a problem. My initial way of writing this script: ELEM=`ls -l $DIR | wc -l` if [ $ELEM -lt 5 ] ; then Which works. However I want to move my $ELEM into the conditional parameter block so it can be interpreted when I reach ...

Starting and stopping a process daily using the shell?

I know I can start the process with cron, but how would I go about stopping it? I thought about starting a new process1 everyday at 00:00, then at 23:59 I'd start a process2 doing ps -aux | grep process1, getting the pid from the line and then killing it, but I was wondering if there's be a better way to do it. I could use Python or Jav...

How to accomplish a logical exclusive OR in bash

I'd like to have a command only execute if the preceding command's exit status was not 0. i.e. Command 1 ^ Command 2 where Command 2 is only executed when Command 1 fails. ...

Cron bash script leaves cron [defunct] lingering..

Hi! I'm running the below script with cron, in /etc/cron.d/mycron I have the following: */10 * * * * MyUserThatNeedsToRunTheScript /backup/sshconnect.sh However, looking at ps -aux I find that a few [defunct] processes are lingering, any ideas? Does this have to with SSH being run with -f ? 5 0 1598 641 20 0 2552 1068 p...

In bash, can the file operator (-f) be case-insensitive?

I'm doing the following: if [ -f $FILE ] ; then echo "File exists" fi But I want the -f to be case-insensitive. That is, if FILE is /etc/somefile, I want -f to recognize /Etc/SomeFile. I can partially work around it with glob: shopt -s nocaseglob TARG='/etc/somefile' MATCH=$TARG* #assume it returns only one match if [[ -f...