Programming :: Passing Arguments To A Bash Source File?

Apr 24, 2010

Is it possible to pass arguments to a source file in a bash script? For example

. /dir1/dir1/funclib -a -b

How would you check for the passed arguments in funclib without getting confused with any arguments passed to the main script?

View 5 Replies


Ubuntu :: Incrontab Not Passing Arguments To Bash Script

Feb 28, 2010

It seems incrontab wont see spaces properly at all. I setup a script to echo the arguments passed to it by incrontab to a file, and no matter what I put around the arguments on the incrontab file it will count a space as the next argument.

I have written a script to automatically retrieve imdb artwork for a given filename. Here is the script:


You can ignore all the commented "echo" commands that was just me testing. Anyway, the script work fine, however I am trying to use incrontab to monitor a folder, when a new (video) file is moved into the folder, it should execute the script and retrieve the artwork. My problem is, when incrontab passes the $# argument to my script, the script wont work because the spaces aren't escaped.

Here is some more detail:




The problem is, the script GetArtwork, doesn't see "Bangcock Dangerous" it just sees "Bangcock"

I have tried putting quotes around the $# in the incrontab - this just makes the script see "Bangcock (notice the single quote character)

View 2 Replies View Related

General :: Passing Commands As Arguments To Functions In Bash Script?

May 31, 2010

I wrote a simple bash script to let me treat any set of programs like a deamon. For example if I configure the script a certain way I can start/stop/get the status of apache, mysql and php all from one command. I am having a bit of a problem though. I am passing commands as strings to a function and then depending on the arguments to the script it might run one of these commands or another. Some of these commands need to beun in the background though, such as deluge-web. When I send "deluge-web &" to the function and it execute it deluge-web does not start in the background. I can't figure out why this is. I have tried escaping the & with ''s and with a , but nothing seems to work. I know that this is some idiotic thing that I am overlooking, but I am a bit stumped. Here is the script configured to start/stop/get status of deluged and deluge-web.

function checkanddosomething {


View 3 Replies View Related

Ubuntu :: Parsing Textfiles And Passing Arguments In Bash To Preserve Tracker-tag Metadata

Sep 3, 2010

I'm at the bottom of the bash learning curve, looking up, hoping someone can toss me a line. I need to update tracker on my system but this will erase the metatag database I've been building up over the course of months for the purpose of indexing a news archive. So the solution seems to be, 1) save the output of tracker-tag to a text file for all relevant files within a directory, 2) upgrade tracker (since the version in the Ubuntu repositories is very much out of date) and then 3) use a script to parse the text file and pass appropriate arguments back to tracker-tag to rebuild the database. It sounds as though it ought to be simple enough, but I need a push in the right direction, which hopefully will not be off the cliff. Before I confuse my metaphors any further, here's what the text file looks like.


View 3 Replies View Related

Programming :: Passing Arguments To A Child Process In C++?

Feb 7, 2010

what I am trying to do is to pass an argument to the standard input stream of a child process. I mean I create two programs .. first one invokes the other. second one contains something like


scanf("%d", &n);

now I want my first program to be able to pass a value to the second one so that it gets stored in n.

View 7 Replies View Related

Programming :: Passing Arguments To System Command?

Dec 17, 2009

I am calling another executable in my application (C programing) using "system" command
which is user interactive program. now i want to pass those args in system command only.

system(" executable ");

Executable will expect 1,2 or 3.

1 is to continue
2 for do changes in settings
3 exit from application

how to pass these in to system command

View 1 Replies View Related

Programming :: Syntax For Passing Arguments In Csh Aliases?

Mar 22, 2009

I want to write a little time-saving alias for my .cshrc file that will move files and then cd to the directory I've moved them to. What I can't quite figure out is the syntax to say 'move all the arguments except the last one.' Here is what I have:

alias follow 'mv !:1-$-1 !:$; cd !:$'

This actually seems to work, but it also gives me an irritating error:

mv: cannot stat `destinationdirectory/-1': No such file or directory

Similarly, I tried:

alias follow 'mv !:*$#argv-1 !:$; cd !:$'

Again the move and cd are successful, but again there is an error:

mv: cannot stat `destinationdirectory/0-1': No such file or directory

View 1 Replies View Related

Programming :: C Syntax - Passing In Unknown Number Of Arguments?

May 18, 2009

I need to write a wrapper function around the mvprintw function, like so:

int smvprintw( ? )
// Do various checks/modifications on the first two arguments (int y,
int x) first,
// and then
return mvprintw ( ? );

How should I write the args for smvprintw so that I can pass all the data correctly to mvprintw, and also do my checks on the first two args (for example, to modify them)? I'm confused by the prototype of mvprintw: This is mvprintw as listed in the man pages:

int mvprintw(int y, int x, const char *fmt, ...);

And this is how I saw it in ncurses.h:

extern NCURSES_EXPORT(int) mvprintw (int,int, const char *,...)

I believe the "..." refers to the unknown number of items after const char * fmt. Will it suffice to do something like "int smvprintw(int y, int x, const char * fmt, void * etc)" and then "mvprintw(y, x, fmt, etc)" inside the function?

View 2 Replies View Related

Programming :: Case Statement Passing Multiple Arguments?

Aug 7, 2010

I've started dabbling with the case statement in order to pass some option's arguments into variables. I do not think I am doing this right.


usage() {
echo "Usage: $0 [-z|--snooze] [-c|--channel] [-p|--playlist]
[-m|--message] [-v|--mpcvolume]"


As you can see, I want to pass arguments depending on the option(s) chosen by the user; ie. --snooze, or --channel. By default, if no options are chosen, I'll display a usage message; though in the future I'll provide some sane defaults. I'd like to create a case statement to handle passing arguments to any number of options; something like:

Code: --snooze 20 --message 'wake up!'

and for the other arguments, it would have a default set. The case statement I provided fails with a syntax error "syntax error near unexpected token `$2'" near the '--snooze' in the statement, so I take it you can't pass a parameter in this way; but I'm confused as to how I'm supposed to pass different parameters to different options without the options being confused as parameters.

View 2 Replies View Related

Programming :: Passing Command-line Arguments To Qglviewer Application?

Jul 13, 2009

how to use QGLviewer. I want to give my program a file name as a command line argument. All of the sample programs I find have a main.cpp file like this:


#include <QApplication>
#include "window.h"
int main(int argc, char *argv[])


Then the Window class, which is derived from QGLViewer, does all the program's actual work. If I want access to argc and argv, for example, to open and read a file that's passed as an argument, what would handle that? Is there a built-in way to get the arg variables to the window class, or do I need to just write a loadfile function and pass them?

View 1 Replies View Related

Programming :: Passing A Source Ip To The Server?

Jan 12, 2011

i'm programming a small tcp client, but i need that the server knows the source ip. My client receives a external connection and forwards, but the ip seen by the server, of course, is the client ip. I would like, change this ip to original source ip.

I don't know how to do this. I tried with the connect and select function.

View 5 Replies View Related

Programming :: Bash Reading Arguments, Most Effective Way?

Aug 17, 2010

I've been reading about getopt and getopts but it doesn't seem like it's possible to parse arguments like --foo or even -foo. I've started my own script trying to achieve this, but I'm still wondering if I'm losing performance and if there is a better way to do this task.

Also I'm using the [[ =~ ]] regex syntax which seems to be available only in newer bash versions, should it be a big issue? My bash version: GNU bash, version 4.1.7(2)-release (x86_64-unknown-linux-gnu)


View 6 Replies View Related

Programming :: Read Multiple Arguments In Bash Script?

Nov 24, 2010

First, I made a simply script which let me download a file from a filehosting site on my server, but I can only put one link there, so I need help how to put multiple links in.Here is my script:

echo "Enter URL:"


View 3 Replies View Related

Programming :: Make 2 Separate Arguments In 1 Bash Script?

Aug 31, 2010

This is what I have:



View 8 Replies View Related

Programming :: Bash - Passing Variable To Ssh?

May 8, 2010

I have a file with around 1000 IP addresses in it and I need to be able to ssh into each one of them, run a single command, and then exit. I already know the ssh command I want to run and it looks like this:


shpass -p [password] ssh -p 10022 -o StrictHostKeyChecking=no root@[ip variable] 'reboot'

(I know shpass is not good to use and keys are the correct way but I don't have any other options in this scenario.) if these ip addresses were in a .csv file, by themselves with no other information, how would I create a script to do the above command to each ip until the end of the file?

View 8 Replies View Related

Programming :: Passing A Variable To Bc In Bash ?

Jan 14, 2009

I cannot for the life of me get this little (simple) script I wrote to work. Here is the entire script:


ASPECT=`mediainfo $1 |grep "Display aspect ratio" |cut -d : -f 2`
HEIGHT=`echo "320 / $ASPECT" |bc`
SIZE=`echo 320x$HEIGHT`


An input filename ($1) is fed into mediainfo, which by the use of grep and cut spits out a single number which is the aspect ratio. This is then divided by bc into 320, which gives the desired height dimension for the file that I want ffmpeg to create for me. Finally, ffmpeg runs using the calculated dimensions... Basically, it's the passing of the $ASPECT variable to bc that seems to fail. It looks like bc won't read the output from the mediainfo line... It always crashes out with:


(standard_in) 1: illegal character: ^M I've tried doing something even simpler like this to debug by just trying it to display the calculation on the screen:


ASPECT=`mediainfo $1 |grep "Display aspect ratio" |cut -d : -f 2`
HEIGHT=`echo "320 / $ASPECT" |bc`
echo $HEIGHT

and it does the same, so it's definitely bc that won't accept the output from mediainfo.

View 4 Replies View Related

Programming :: Bash Script : Pass Arguments To Second Level Parser?

Jan 14, 2011

I wrote a C++ program that uses two different parsers. The first parser is reading program arguments from command line:./mybin arg1 arg2 ...then during program execution there's an interactive prompt asking for more parameters:

>> (second bunch of arguments here)

I'd like to run my program inside a bash script, but I don't know how to give the second level arguments.

View 2 Replies View Related

Programming :: Passing PHP To Bash Script And Then Back?

Jul 15, 2010

I have a bash script called bash I am trying to execute from PHP. I think I have that right (not sure yet). Ideally let me explain what I am doing. The front end will pass a variable from a text entry box, called New_Task, the New_Task needs to be executed in the bash script and the output needs to be displayed back on the front end. So let me give some code and let me know what you all think.bash code is quite long, but essentially it is made to take a entry and create a task out of it. eg. "svn branch <Task Name>". The code below is getting the New_Task variable passed from the text entry box ($NewTask) and I have an exec for the bash script, but I am not sure it is working, I need to add some code to see the input in the front end.PHP back end code:PHP Code:

function mTaskCreator()
$strAction = $this->_objUserContext->mGetPostVar( 'acti


View 7 Replies View Related

Programming :: Passing Parameters From C Code To Bash Script

Apr 16, 2011

I get no print to stdout on screen from the C code.Does bash somehow block or mask it?I get print from bash. I get this error in the non-test bash script like: let "rdval = $rdstr"syntax error: operand expected (error token is " ")The let command prints rdval= but I presume this is due to the printf test statements getting in the way.I am getting no compile errors. Why does the C code not print the values specified?

View 2 Replies View Related

Programming :: Bash: Passing Output To Another Programs Input?

Nov 12, 2009

I am not sure if that Subject really explains it, basically I have a script that executes a CLI java-applet that requires a passphrase from the user. I can easily execute this by issuing the -p argument followed by the passphrase however that shows up on possible logs or at least on the results of the ' ps ' command. If you do not supply this -p argument it provides a new line with the echo " Enter Passphrase: " and asks for input.

how can I provide a result/input for the Passphrase request and is it still possible to throw this application in the background with the ' & ' following the command? I have seen a few examples that show a /bin/expect that expects a result and sends a command however I would like to refrain from any extra dependencies. Example of Regular Execution of application:


$ /usr/local/***/**** -u USERNAME -r Default-Realm -f certificate.der

View 6 Replies View Related

Programming :: BASH Conditionals - Passing Condition As Variable ?

Sep 17, 2009

I'm trying to implement an assert function similar to:[url]

However, I'm having trouble with file existence testing when the file name has a space in it.

I have distilled the problem down to the following:

This code works as expected, printing 'yes' if '~/test file' exists, and no if not.


However, this code gives an error.


The error:


Which tells me that it is splitting ["~/test file"] into ["~/test] and [file"]. Why? Is there a way around this?

Note that if you simply use a file path without a space, both cases work perfectly. Is this a BASH bug possibly? I just can't understand why the first would work, but the second wouldn't.

View 8 Replies View Related

Programming :: Python Passing Multiple Args To Bash

Jan 14, 2011

I have a text string I want to pass as the second arg to a bash shell.

My python line is :

The first arg "gap" works great and the bash shell uses it as $1

I need "fill" passed along as $2 intact

Here is the bash line:

As you can see after the -f it has to be in single quotes and $FILL will complete the single quote

Nothing is getting passed as a second arg from python, I did have the first word at one time but that was 85 tries ago and forgot how I did it!

The bash script complains about an unterminated quote.

View 6 Replies View Related

Ubuntu :: Passing Arguments In Commandline

Mar 13, 2011

I have some source code of an application called gmapping.

I am pasting the source code documentation below:


How do I run this file. When I enter the filename parameter, and press enter, I get

COMMAND LINE: parameter aces not recognized no filename specified

GridFastSlam: Initialization Error!

(Did you specified an input file for reading?)

What is the right line to type in the terminal to sun this code?

View 1 Replies View Related

General :: Passing Program Arguments To Gdb?

Nov 18, 2009

I'm using gdb to debug my program. My program requires arguments (e.g., ./prog -dfile).But if I use gdb as in gdb ./prog -dfile, gdb wants to interpret the -d argument. How do I pass an argument to my program via gdb?

View 2 Replies View Related

General :: Passing An Array As Command Line Arguments?

Apr 2, 2011

how to pass an array as a command line argument in a shell script?

View 5 Replies View Related

General :: Passing Multiple Arguments In Shell Script?

Dec 11, 2010

The script receives multiple files as parameters and it is supposed to count the number of lines in each of them and write that number in another file.

This is my script:


while [ -n "$1" ]
lines=`cat $1 | wc -l`
echo "The number of lines in file $1 is $lines." >> lines.txt

Is there any other way to do the same thing, without using shift?

View 7 Replies View Related

General :: Scripting - Try To Passing Arguments To For Cycle - Inside A Function

Apr 26, 2011

The code:


Problem: I need a method to maintain the $i variable. In fact, actually, this variable get lost when executed. I think that an escape can preserve this variable and permit its execution inside the function, but I've no idea about.

View 3 Replies View Related

Programming :: Script By Passing A FILE Without Executing It?

Mar 20, 2010

what i did is created a file called pro3types but the script starts & by pass the file. i added +x to file ran the process but still no luck. i was wondering what else i should change to get the menu to the sub-categories of product3 after users selecting it. all I need to get the pro3types runs after users selecting product3 from the previous menu. need more info please see the thread: "Adding New Selections to the existing Script"


but here is code:


export -n selecttypechoice


View 5 Replies View Related

Programming :: Bash Script: Passing Values From Script To A C++ Executable?

Mar 4, 2011

I've been searching the forums and google in an attempt to find an answer. I'm completely new to scripting and just want to get one or two up and running but I'm having problems with my current script. I want the script to:read my inputs run a loop in certain steps
within the loop execute a program with output to another file enter the values into the program (Problem area)


echo "Enter the Lower value, followed by [ENTER]"
read L
echo "Enter the number of steps you want to take, followed by [ENTER]:"
read s


Running the program from the shell asks for 3 variables, which in my script are i, tt and adstep. I understand conceptually why it won't work. It won't move onto the next line in the loop until the previous task is completed (which doesn't even start without the 3 inputs!)

View 3 Replies View Related

Programming :: Bash Script - Source Not Found

Feb 25, 2011

I want to edit the environment with a bash script, a part of my script is showed in the post. Its not everything, but the rest is working fine. At the begin of my script I've the follow line Code: #!/bin/bash
set -e First I tried with this solution. Code: sudo chmod 777 /etc
sudo rm /etc/environment
echo 'PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/ruby/bin"' > */etc/environment
sudo chmod 755 /etc
source /etc/environment Error, source not found

The second solution was this:
Code: sudo chmod 777 /etc
sudo rm /etc/environment
echo 'PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/ruby/bin"' > */etc/environment
sudo chmod 755 /etc
. /etc/environment
This one didn't give an error, but if I try this:
Code: ruby -v got an error
so the environment didn't worked.

If I use both commands
Code: source /etc/environment
Code: . /etc/environment
In the terminal, without a bash script, it works, so if I do
Code: ruby -v
It works and showed the right version.

View 6 Replies View Related

Copyrights 2005-15, All rights reserved