Visit The New, Modern Unix Linux Community

Full Discussion: Bash function problem
Top Forums Shell Programming and Scripting Bash function problem Post 302985958 by dagamier on Thursday 17th of November 2016 10:44:29 AM
Bash function problem

I am trying to figure out why I am having a "problem" with some functions in a bash script I am running. The reason for air quoting is that the functions are working, they are just not displaying anything to screen when called from another function. Here's an example:

Code:
function Create_Input
{
read -p "Enter customer name: " CUSTOMER
read -p "Are you including SST data? <Y/N> " SST_DATA

case $SST_DATA in
  [yY]) make_sst_data
      ;;
  [nN]) make_no_sst_data
     ;;
  *) bomb
    ;;
esac
}

In the two "make" functions, I call a spinner and I run some additional commands, but none of the output goes to screen until at the last second when everything completes (I have a sleep to pause so I can see anything that would be missed by just exiting back), then I can see it ran things. The script is going to be used by others and I put in visual queues for people to see that things are running (like the spinner as it processes files), but none of those references are coming through. The case statement itself is inside of a function that does some validations first and prompts the user for some required inputs.



Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 11-17-2016 at 12:54 PM.. Reason: Changed ICODE to CODE tags.
 
Test Your Knowledge in Computers #289
Difficulty: Easy
Sun Microsystems was acquired by Oracle Corporation in 2012.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need assistance with bash function

Hi all! I need a little help with an imbedded fuction I am trying to write. What I am trying to do is go to a series of hosts and get the contents of an XML file, storing some of the data, along with the name of the host it was gathered from. My intent is to store this in an array for later... (1 Reply)
Discussion started by: _jade_
1 Replies

2. Shell Programming and Scripting

Need help in using power function in Bash

Hi, I would like to use a power function in Bash in an awk '{ } . e.g pow(2,3)=8 Any suggestion? I try to find online resources but most of them stated by using BC. Please advise. Thanks. (3 Replies)
Discussion started by: ahjiefreak
3 Replies

3. Shell Programming and Scripting

bash search function

I want to have a function with a similar interface: search *.cpp asdf that will search recursively all directories for *.cpp file, containing line 'asdf' inside. I tried this: function search { find . -name "$1" | xargs grep -li $2; } But it doesn't work all the time. For example, if i run it... (3 Replies)
Discussion started by: doze
3 Replies

4. UNIX for Advanced & Expert Users

AWK sub function curious problem under bash

I need to detect the number of pages in a print job when it is available so I can warn users when they try to print a report much larger than they expected. Sometimes they are trying to print 1000 page reports when they thought they were getting a 10 page report. Under linux I am scanning the... (5 Replies)
Discussion started by: Max Rebo
5 Replies

5. Shell Programming and Scripting

BASH function error

Hey everyone. I am currently testing my first function based BASH script. The ultimate goal is going to be moving logs from point A to point B (or if B is down, to point C). Part of this involves the following function: function testAlive{ ping -c 1 -q $1 } Now when I run ping -c... (1 Reply)
Discussion started by: msarro
1 Replies

6. Shell Programming and Scripting

Bash function

startvm() { startguest } Is there a way use one line to get this ? actually I want startvm=startguest (5 Replies)
Discussion started by: yanglei_fage
5 Replies

7. UNIX for Dummies Questions & Answers

Bash INKEY$ function...

This is probably common knowledge to the professionals but not so much for amateurs like myself. This is a code snippet for the equivalent of BASIC's... LET char$=INKEY$ As the timeout parameter cannot be less than 1 second then this is the only limitation... It is a single line... (5 Replies)
Discussion started by: wisecracker
5 Replies

8. Shell Programming and Scripting

Yes or No selection within bash function

I need to add a selection within the bash function below and am having some trouble doing so. phox2b() { printf "\n\n" printf "What is the id of the patient getting Phox2B analysis : "; read id printf "Is this an intronic variant? Y/N "; read match_choice case... (5 Replies)
Discussion started by: cmccabe
5 Replies

9. Shell Programming and Scripting

Bash function, for BSD

I am putting this thread to shell-threads, because it is about how to make a function work properly. I need a hint for declaring a function right, it has been more than a year I did not work that straight with bash. So my aim is to turn off the eth0 (as it would be in linux, and bge0 in bsd ),... (2 Replies)
Discussion started by: 1in10
2 Replies

10. Shell Programming and Scripting

Bash script: problem with a function which use colors

Hello guys :) I've a some issue with a function which use the bash colors in my script. An example : #!/bin/bash set -x log_in(){ host="srv1" remote_files="log/" LOG_FILE="logfile" green='\033]; then color_in_red=("${red}"$2"${none}") echo -e... (2 Replies)
Discussion started by: Arnaudh78
2 Replies
Twiddle(3pm)						User Contributed Perl Documentation					      Twiddle(3pm)

NAME
Term::Twiddle - Twiddles a thingy while-u-wait SYNOPSIS
use Term::Twiddle; my $spinner = new Term::Twiddle; $spinner->start; system('tar', '-xvf', 'some_phat_tarfile.tar'); $spinner->stop; $spinner->random; ## makes it appear to really struggle at times! $spinner->start; &some_long_function(); $spinner->stop; DESCRIPTION
Always fascinated by the spinner during FreeBSD's loader bootstrap, I wanted to capture it so I could view it any time I wanted to--and I wanted to make other people find that same joy I did. Now, anytime you or your users have to wait for something to finish, instead of twiddling their thumbs, they can watch the computer twiddle its thumbs. During Twiddling Once the twiddler/spinner is in motion you need to do something (e.g., unpack a tar file, call some long function, etc.). You can do almost anything in between start and stop as long as there are no sleep calls in there (unless the process has been forked, as in a Perl system call). From Time::HiRes: Use of interval timers may interfere with alarm(), sleep(), and usleep(). In standard-speak the "interaction is unspecified", which means that anything may happen: it may work, it may not. Try not to do any terminal I/O while the twiddler is going (unless you don't mind dragging the twiddler around with your cursor). Spinner Methods new Creates a new Twiddle object: my $spinner = new Term::Twiddle; Optionally initializes the Twiddle object: ## a moderately paced spinner my $spinner = new Term::Twiddle( { rate => 0.075 } ); start Starts the twiddler twiddling: $spinner->start; stop Stops the twiddler: $spinner->stop; thingy Creates a new thingy. The argument is a reference to a list of strings to print (usually single characters) so that animation looks good. The default spinner sequence looks like this: $spinner->thingy( [ "\", "|", "/", "-" ] ); an arrow could be done like this: $spinner->thingy( [ "---->", " ----->", " ----->", " ----->", " ----->|", " ---->|", " --->|", " -->|", " ->|", " >|", " |", " "]); Look at the test.pl file for this package for more fun thingy ideas. rate Changes the rate at which the thingy is changing (e.g., spinner is spinning). This is the time to wait between thingy characters (or "frames") in seconds. Fractions of seconds are supported. The default rate is 0.175 seconds. $spinner->rate(0.075); ## faster! probability Determines how likely it is for each step in the thingy's motion to change rate of change. That is, each time the thingy advances in its sequence, a random number from 1 to 100 is generated. If probability is set, it is compared to the random number. If the probability is greater than or equal to the randomly generated number, then a new rate of change is randomly computed (between 0 and 0.2 seconds). In short, if you want the thingy to change rates often, set probability high. Otherwise set it low. If you don't want the rate to change ever, set it to 0 (zero). 0 is the default. ## half of all sequence changes will result in a new rate of change $spinner->probability(50); $spinner->start; do_something; $spinner->stop; The purpose of this is to create a random rate of change for the thingy, giving the impression that whatever the user is waiting for is certainly doing a lot of work (e.g., as the rate slows, the computer is working harder, as the rate increases, the computer is working very fast. Either way your computer looks good!). random Invokes the probability method with the argument specified. If no argument is specified, 25 is the default value. This is meant as a short-cut for the probability method. $spinner->random; stream Select an alternate stream to print on. By default, STDOUT is printed to. $spinner->stream(*STDERR); Alternative Spinner Methods Since version 2.70, Term::Twiddle objects support a couple of new spinners that aren't so "plain". 2.70 includes a bounceing ball and a swishing object (that's the best name I could think to call it). The following methods are used to activate and customize these new spinners. type Use this method to set the type of spinner. The default type (no type) is whatever thingy is set to. Two other currently supported types are bounce, and swish. These may be set in the constructor: my $sp = new Term::Twiddle({ type => 'bounce' }); $sp->start; or you can set it with this type method: my $sp = new Term::Twiddle; $sp->type('bounce'); There is currently no way to add new types without some hacking (it's on the "to do" list). width This method is only used when type is undefined (i.e., a normal spinner). width determines how wide the bounce or swish objects go. width may be set in the constructor: my $sp = new Term::Twiddle({ type => 'bounce', width => 60 }); $sp->start; or you can set it with this width method: my $sp = new Term::Twiddle({ type => 'swish' }); $sp->width(74); delay Determines the speed of motion of the object. Usually the default is fine (and each object has its own default delay option for optimal aesthetics). EXAMPLES
Show the user something while we unpack the archive: my $sp = new Term::Twiddle; $sp->random; $sp->start; system('tar', '-zxf', '/some/tarfile.tar.gz'); $sp->stop; Show the user a bouncing ball while we modify their configuration file: my $sp = new Term::Twiddle( { type => 'bounce' } ); $sp->start; ## there must not be any 'sleep' calls in this! do_config_stuff(); $sp->stop; AUTHOR
Scott Wiersdorf, <scott@perlcode.org> CAVEATS
o Prolly won't run on platforms lacking setitimer. Will run on Cygwin/Win32 (reported by Zak Zebrowski--thanks!). o ACKNOWLEDGEMENTS
o Thanks to Tom Christiansen for the timer code (found lurking in an old FAQ somewhere). He probably never had an idea that it would be part of one of the most useful modules on CPAN ;o) The timer code has since been replaced by Time::HiRes's setitimer function, but it is good to thank Mr. Christiansen for his goodness to Perl anyway. o "Drew" (drew@drewtaylor.com) from rt.cpan.org for suggesting the removal of 'use warnings' for the faithful 5.005 users. o Orignal swishing motion filched from Term::ReadKey's test.pl by Kenneth Albanowski (kjahds@kjahds.com). Danke! SEE ALSO
perl. perl v5.10.1 2010-08-08 Twiddle(3pm)

Featured Tech Videos

All times are GMT -4. The time now is 04:04 PM.
Unix & Linux Forums Content Copyright 1993-2020. All Rights Reserved.
Privacy Policy