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:

Code:

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

[code]......

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:

Code:

(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:

Code:

#!/bin/bash
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


ADVERTISEMENT

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:

Code:

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 :: 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.

Code:

However, this code gives an error.

Code:

The error:

Code:

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

Debian Programming :: Passing Variable Between Invocations

Jan 9, 2014

I want to build on the code from /etc/apt/apt.conf.d/05etckeeper to work with Snapper, the new-in btrfs (et al) snapshot package.

Code: Select allDPkg::Pre-Invoke       { "if [ -x /usr/bin/etckeeper ]; then etckeeper pre-install; fi"; };
DPkg::Post-Invoke      { "if [ -x /usr/bin/etckeeper ]; then etckeeper post-install; fi"; };

The etckeeper code will work well as a template, but I need to pass a parameter between the pre- and post- instances. The parameter is obtained from the pre- invocation and passed to the post- invocation.I know that something similar to my quest is done with the 'pid' but how to do it in the 'standard' way. Happily there can't be multiple dpkg instances running concurrently (prevented by dpkg?) so I don't have to worry about that issue.

Q1. What is the 'standard' way of passing parameters about?

Code: Select allsnapper -c etc create -t pre  -p     (which 'prints' the parameter (int) to pass to the following invocation)
snapper -c etc create -t post --pre-number  <parameter>  in place of the two etckeeper calls.

Q2. How do I pick up the 'printed' output of the 'pre' call? I think it's just a 'get' from the stream but perhaps I've missed something.?

View 2 Replies View Related

Programming :: Passing Local Variable Pointers In ASM

Apr 12, 2010

I want to know is there some more efficient way of passing a pointer to a local variable as a parameter to a function in x86 asm? Right now I have to move the base pointer to a temp register, subtract from the register and pass that, like this (assuming a local var at esp-4):

Code:
mov eax, ebp
sub eax, 4
push eax
Is there a better way?

View 8 Replies View Related

Programming :: Passing Variable To Oracle Query With PHP

Jul 11, 2011

I'm having some trouble this morning to send a SQL query to our Oracle DB server in PHP. When I try to pass my value "OF/110246801A01" as variable it tell's me "Warning: oci_bind_by_name(): ORA-01036: illegal variable name/number"

PHP Code:
$ociO ='OF/110246801A01';
$selectAllFieldsFromOf=oci_parse($conn,"SELECT*FROMMFGOPEWHEREMFGNUM_0LIKE':ociOf' ");
oci_bind_by_name($selectAllFieldsFromOf,":ociOf",$ociOf,15);
$resultQuery =oci_execute($selectAllFieldsFromOf);
if(!$resultQuery){
$e = oci_error($selectAllFieldsFromOf);
return trigger_error(htmlentities($e['message'],ENT_QUOTES),E_USER_ERROR);
[Code]....

View 1 Replies View Related

Programming :: C++ Passing Pointer Variable As A Reference Parameter

Jan 21, 2011

Say, i have an imaginary std library function, which I want to call.

Code:
void std_lib_func(ObjectType *param);

Now in my c++ program, I have a main() function, and I will like to call a customized function (which will in turn call the std lib function) from the main function, as below:

Code:
int main()
{
ObjectType *aobj;
customized_func(aobj);
}
[Code]...

I tried the below but get an error that the std lib function is expecting a ObjectType* param, not aobj. How should I work this out.

Code:
void customized_func(ObjectType aobj)

View 4 Replies View Related

Programming :: Passing Perl Variable Into Input Tag In Cgi Script?

Aug 27, 2010

How can I to pass a perl variable into html input tag? For example, If a have got a cgi script:

Quote:

use CGI;
use DBI;
my $owner = $cgi->param('owner');

[code]....

How can I to pass $owner variable?

View 1 Replies View Related

Programming :: Passing A Variable At Compile Time - Send POSITION

Jan 14, 2010

I want pass a variable at compile time.

for example in x.c
int global_var = POSITION;

How can I send this POSITION at compile time. ie like # make POSITION=10 Is it possible?

View 5 Replies View Related

Programming :: Bash - Read Content Of File To Variable And Use This Variable In For Loop ?

Aug 21, 2009

I'm trying to read content of file to variable and use this variable in for loop. The problem is, when I have c++ comment style in file - /*. Spaces in line are also interpreted as separated lines.

For example:

Code:

Changing $files to "$files" eliminate these problems but causes that whole content of variable is treated as one string (one execution of loop).

View 6 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

[code]...

View 7 Replies View Related

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

#!/bin/sh
#
. /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 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:

Code:

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

View 6 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

Programming :: Reading A Bash Variable In Bash Scripting ?

Nov 26, 2008

I have a config file that contains:

my.config:

Code:

Now in my bash script, I want to get the output /home/user instead of $HOME once read. So far, I have managed to get the $HOME variable but I can't get it to echo the variable. All I get is the output $HOME.

Here is my parse_cmd script:

Code:

View 3 Replies View Related

Programming :: SH: Passing A Variable Out Of A "while - Do - Done" Loop

Jul 3, 2011

"While ; do ; done" is very convenient for SH coding. However sometimes you may be annoyed by your computed variable within the "while do done" type loop. What to do how to pass it out of the loop to the outside of the bash code? A solution is to write it into the /tmp or on the disk... and to call it back after. - not elegant... really not... Anyone would know a trick another alternative that would look nicer?

Code:
# Count file total size
TOTAL_SIZE=0
LISTOFFILES=`cat "$HOME/.fvwmoscfg/fvwmburnerlist.lst"`
echo "$LISTOFFILES" | while read i ; do
SIZE=`du -bs $i | cut -f 1`
TOTAL_SIZE=`expr $SIZE + $TOTAL_SIZE`
echo "$TOTAL_SIZE" > "$HOME/.fvwmoscfg/fvwmburnerlisttotalsize.lst"
done
TOTAL_SIZE=`cat $HOME/.fvwmoscfg/fvwmburnerlisttotalsize.lst`

echo "The total size of all files and folders is : $TOTAL_SIZE"

View 8 Replies View Related

Programming :: Sed A Variable In Bash?

Mar 25, 2011

I have beat this enough and don't get what should have been a very simple thing to do. I build a variable;

Code:
CLIST=java,lua,python,php,perl,ruby,tcl
CLIST will be used by another bash script but I need to replace the commas with a space. I

[code]...

View 2 Replies View Related

Programming :: Variable Substitution In BASH?

Feb 17, 2011

Just a simple BASH for loop to read the file path from a text file (clean.txt) echo the variable for debug purposes, and scp it to a server I have using port 50 for SSH.

I've already formatted the entries in clean.txt to handle spaces correctly, using sed replacement.

Example from the clean.txt file:

Code:
/MP3/NAS000000001/Barenaked Ladies/Barenaked Ladies - Barenaked For The Holidays/20 Auld Lang Syne.mp3
/MP3/NAS000000001/Barenaked Ladies/Barenaked Ladies - Barenaked For The Holidays/14 Deck the Stills.mp3

[Code]....

View 5 Replies View Related

Programming :: How To Use Bash Variable In C Code?

Feb 16, 2011

I want to write a c program with some shell scripts.Now For a simple C program. I am Setting a variable called val2 in bash, now I want to use bash variable val2 in C code. How do I do that?The above doesn't work (coz its spawning a different memory space and when shell script ends the variable dies with it as per my research but how do I keep them in same memory space)Also Is there any Good reference where they teach how to integrate C and Bash Together?

View 5 Replies View Related

Programming :: (BASH) Keep Variable In Scope?

Jul 15, 2011

i've just started to learn about functions in Bash scripting. I'm able to set the functions and execute the commands correctly. However, if my_var is set in the first function and then later in the script in the script the 2nd function is called, it doesn't seem to remember my_var and quits (at least i suspect this is the problem).

Here's my code (it requires yad available via webupd8. org). My specific problem seems to lay in line #27 where if we view the changelog and then exit that window, it returns to the "main" function but any subsequent commands cause a crash. Is this because of the get command on line #29? It's presumably now out of scope after calling menu on line #25?

View 8 Replies View Related

Programming :: Setting Variable In Bash With Sed?

Jun 18, 2011

I am killing myself with this, please someone come to the rescue...

Code:
#!/bin/sh
IFILE=$@

[code]...

View 7 Replies View Related

Programming :: Bash Concatenating String To Variable ?

Jan 18, 2011

I have a program that loops over each word in a sentence. I need to append a constant to the beginning and end of each word. It works up until the last word on the line.

Code:

Output:

View 4 Replies View Related

Programming :: Bash: Give A Variable The Value Of A Function?

Aug 8, 2010

I was wondering if possible in bash for a variable to take the value of a function, I mean the function returns a value and a variable will take it. example:

[Code]....

View 3 Replies View Related

Programming :: BASH - If Variable -eq String Not Working ?

Jan 24, 2010

Here is the code:

Code:

How ever when I run this script I get the following error

Quote:

I just don't get it, I have racked my brain trying to figure out every combination of how I should write this if statement and I can't get it to work.

View 2 Replies View Related

Programming :: Bash: Making A Variable Out Of Two Other Variables?

Mar 18, 2010

I need to find the value of:

Code:
$Namenumber
My script asks for the name you want to look up and I want it to return the value of $Namenumber

I was thinking:

Code:
number=$"$name"number
but this returns

Code:
$Namenumber

but does not actually resolve what the variable $Namenumber is equal to.

View 4 Replies View Related

Programming :: Bash - To Prepend Text To Variable

Feb 13, 2010

The output of following code is not like it's intended ...

Code:

This is the output:

Code:

Test prepending ...apple is a nice word, hour is a nice word, But of course what I want to do in the first set of commands is to prepend the word "an" to the words "apple" and "hour" in the for-loop.

View 4 Replies View Related

Programming :: Bash Redirection With Exec: Specify Fd With Variable?

Feb 21, 2010

Within a bash script, I'm attempting to redirect file descriptors with exec, e.g. exec 3>&1 1>&2; however, I'd like to do something like exec $FD>&1 1>&2, which doesn't work because bash tries to execute the value of $FD. Various placements of eval fail, as well. Is there a way around this, or am I stuck hard-coding the descriptor?

View 3 Replies View Related

Programming :: Grep For Variable In A Bash Script?

Aug 19, 2010

I've tried every combination of ' " that I have come across in similar threads on the forum but no luck.. I have 2 files

strings.txt: contains a list of numbers, 4 digits per line file.
txt: contains a lines that I want to grep for the strings.

for example:

>cat strings.txt
3214
8746
2411

[code]....

if I echo $i in the loop, I print out the contents of strings.txt If I put 3214 in place of grep "<$i>" file.txt I get "carls phone number is 3214"

View 6 Replies View Related

Programming :: Make Bash Replace The Value Of A Variable?

Apr 18, 2009

I have a program I am writing where I have a for loop and I want to make it substitute the variable twice like:

for ((i=0;i<5;i++)) do
echo $"$i"
done

[code]...

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved