Sponsored Content
Full Discussion: Help with Subroutine
Top Forums UNIX for Dummies Questions & Answers Help with Subroutine Post 302488261 by Dalton63841 on Sunday 16th of January 2011 02:08:42 PM
Old 01-16-2011
Help with Subroutine

Okay I have a 1TB drive that is almost completely full with vids. I am in the process of converting them to mp4. I have two scripts right now. One is a shell script to convert them with Handbrake. The other is a script to get a sort of progress report. To make things easier to understand, I will show you that one:
Code:
#!/bin/bash

# Get a numerical progress report
file1=`find . -name *.avi | wc -l`
file2=`find . -name *.mkv | wc -l`
file3=`find . -name *.mp4 | wc -l`
total=`expr $file1 + $file2 + $file3`
mp4per=$((file3 * 100))
percen=`expr $mp4per / $total`

# Print progress as a ratio of converted to total
log1="You have encoded "
log2="$file3 out of $total files."
log3="$log1""$log2"

echo $log3

# Print progress as a percentage
dia1="You have encoded $percen"
dia2="% of your files."
dia3="$dia1""$dia2"

echo $dia3

As you can see this code uses the equation: %=(Number of converted vids * 100) ÷ Total number of vids
It prints out the encoding progress in the form of
"You have encoded 1724 out of 2381 of files."
"You have encoded 72% of your files"

Here's the problem: If I keep this script as its own file, it works perfectly. I can even turn it into a subroutine and call it and it works perfectly as long as it is a separate file, BUT if I put the subroutine inside the Handbrake Encode script and call it, it errors out.

I was just hoping I could combine them together for simplicity's sake, and I feel like I am missing something simple. Any ideas?

EDIT: As extra info, when I turn it into a subroutine inside the other script, it errors saying that the file1, file2, and file3 variables are non-numeric arguments.

---------- Post updated at 01:08 PM ---------- Previous update was at 10:29 AM ----------

LOL nvm everyone. I got it. Turns out the command I was using for the variables file1, file2, and file3 was putting a space before the number and it was tripping it up. Changing it to this did the trick:

Code:
#!/bin/bash

# Get a numerical progress report
file1=`find . -name *.avi | wc -l|sed 's/ //g'`
file2=`find . -name *.mkv | wc -l|sed 's/ //g'`
file3=`find . -name *.mp4 | wc -l|sed 's/ //g'`
total=`expr $file1 + $file2 + $file3`
mp4per=$((file3 * 100))
percen=`expr $mp4per / $total`

# Print progress as a ratio of converted to total
log1="You have encoded "
log2="$file3 out of $total files."
log3="$log1""$log2"

echo $log3

# Print progress as a percentage
dia1="You have encoded $percen"
dia2="% of your files."
dia3="$dia1""$dia2"

echo $dia3


Last edited by Dalton63841; 01-16-2011 at 01:35 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to pass parameter to subroutine

I have something like cp -p <dir>filename1.dat <dir2>filename1.dat there are many other operations in it I mean that filename1.dat will keep on changing I need to write a subroutine so that i can pass filename1 or 2 or 3 .dat as parameter Thanking you in advance Any help wuld be appreciated (2 Replies)
Discussion started by: ssuresh1999
2 Replies

2. AIX

Using the passwdpolicy() subroutine.

Okay, so in AIX, there are various subroutines that is built in to the OS. The subroutine is I want to use is passwdpolicy(). So I want to construct a C program that will be able to pass credentials into the program and thusly into the subroutine. I'm not asking for homework, or for someone to... (0 Replies)
Discussion started by: syndex
0 Replies

3. Programming

Subroutine Hung

Hi friends I am Administrator for a system works with uinx OS but, many times I get messages from server console inform me about Subroutine is Hanging so what can I do to reset this Subroutine? Note: always when I got that I restart the server but I think that is not professional solution. (3 Replies)
Discussion started by: bintaleb
3 Replies

4. Shell Programming and Scripting

Help with a perl subroutine regex

Hi, I can't get this script ot work and I wa wondering if anyone could help? I need to open a file and use a subroutine to search each line for a regular expression. If it matches then I need to return a match from the subroutine and print the result? Any help would be greatly... (11 Replies)
Discussion started by: jmd2004
11 Replies

5. Shell Programming and Scripting

Calling a subroutine with arguments

Hello, I am having problem calling a subroutine with arguments, can any help? is the approach I am using correct? main() { # This is just a subset of the code #$b & $lnum is already define in this section of the code checkboard $b $lnum } checkboards() { ln=$lnum... (2 Replies)
Discussion started by: jermaine4ever
2 Replies

6. Programming

memory allocation in subroutine

Hi everyone, I'm not new to C programming, but I'm having question regarding the memory allocation of a pointer variable which, for instance, will be declared in main(), but its memory will be allocated in subroutine. To clearify my question, I provide a small working example: #include... (1 Reply)
Discussion started by: MIB_Maik
1 Replies

7. Shell Programming and Scripting

Running more than one function from a subroutine

Hi All I am new to perl so had one question. I have one Subroutine which works as expected and below is just an example. where I ran a command and check the output. so my question is if I have more than one command then how to check the results, meaning I want to add more command and check... (2 Replies)
Discussion started by: tannu
2 Replies

8. Shell Programming and Scripting

getopts not updating from subroutine.

So, I'm running a script with a couple of subroutines, one of which takes arguments using getopts. The first time i call the subroutine everything works as expected, the second time I call it none of the arguments change. Here's a small section of code that shows this behavior. #!/bin/sh... (3 Replies)
Discussion started by: dhibbit
3 Replies

9. Programming

perl: Subroutine question

Hi everyone, I have given up finally trying to find a way to do this. I have a subroutine called LoginFirst where I am starting a new SSH session. I have bunch of subroutines, each one of them uses a (or I have to create a new SSH constructor everytime) ssh connection to get some value so ... (2 Replies)
Discussion started by: dummy_code
2 Replies

10. Shell Programming and Scripting

Subroutine or Function Summary

I have a fortran file with code declarations such as Subroutine str_tnum_tu & ( & s, dl, tu, pos & ) ! Class (*), Intent (InOut) :: tu(:) Character (Len=*), Intent (In) :: s, dl Character (Len=*), Intent (In), Optional :: pos ... or ... (11 Replies)
Discussion started by: kristinu
11 Replies
MERGE(1)						      General Commands Manual							  MERGE(1)

NAME
merge - three-way file merge SYNOPSIS
merge [ options ] file1 file2 file3 DESCRIPTION
merge incorporates all changes that lead from file2 to file3 into file1. The result ordinarily goes into file1. merge is useful for com- bining separate changes to an original. Suppose file2 is the original, and both file1 and file3 are modifications of file2. Then merge combines both changes. A conflict occurs if both file1 and file3 have changes in a common segment of lines. If a conflict is found, merge normally outputs a warning and brackets the conflict with <<<<<<< and >>>>>>> lines. A typical conflict will look like this: <<<<<<< file A lines in file A ======= lines in file B >>>>>>> file B If there are conflicts, the user should edit the result and delete one of the alternatives. OPTIONS
-A Output conflicts using the -A style of diff3(1), if supported by diff3. This merges all changes leading from file2 to file3 into file1, and generates the most verbose output. -E, -e These options specify conflict styles that generate less information than -A. See diff3(1) for details. The default is -E. With -e, merge does not warn about conflicts. -L label This option may be given up to three times, and specifies labels to be used in place of the corresponding file names in conflict reports. That is, merge -L x -L y -L z a b c generates output that looks like it came from files x, y and z instead of from files a, b and c. -p Send results to standard output instead of overwriting file1. -q Quiet; do not warn about conflicts. -V Print 's version number. DIAGNOSTICS
Exit status is 0 for no conflicts, 1 for some conflicts, 2 for trouble. IDENTIFICATION
Author: Walter F. Tichy. Manual Page Revision: 1.1.1.1; Release Date: 2002/04/30. Copyright (C) 1982, 1988, 1989 Walter F. Tichy. Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995 Paul Eggert. SEE ALSO
diff3(1), diff(1), rcsmerge(1), co(1). BUGS
It normally does not make sense to merge binary files as if they were text, but merge tries to do it anyway. GNU
2002/04/30 MERGE(1)
All times are GMT -4. The time now is 12:42 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy