Sponsored Content
Top Forums Shell Programming and Scripting How to check for Input Redirection in my script? Post 302408457 by bharath.gct on Monday 29th of March 2010 02:30:55 PM
Old 03-29-2010
Thanks kshji,

I did try that, below is the example where I tried to use the No. of arguments to find the redirection, but that does NOT work for me. And only so I did not post it in my first post.

my.script
Code:
#! /bin/ksh
numargs=$#
case $numargs in
0)
  echo "No. of Args : $numargs"
  echo "Parameter 0 = $0"
;;
*)
  echo "No. of Args : $numargs"
  i=1;
  for d in $@
  do
    echo "Parameter $i = `echo $d`"
    i=`expr $i + 1`
  done
;;
esac

Below are the different runs:
Run 1: Running with NO redirection

Code:
$ ./my.script
No. of Args : 0
Parameter 0 = ./my.script

Run 2: Running with redirection
Code:
$ ./my.script < test.file
No. of Args : 0
Parameter 0 = ./my.script

Run 3: Running with arguments
Code:
$ ./my.script Hi this is a test text
No. of Args : 6
Parameter 1 = Hi
Parameter 2 = this
Parameter 3 = is
Parameter 4 = a
Parameter 5 = test
Parameter 6 = text

Hope this helps! Let me know if you need any more information.

Thanks
Bharath
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Input Redirection

Hi everybody, first of all i am a new member in UNIX.com and this is my first post. I am impressed with the amount of information a person can ever have in this forum, it is really great having something similiar; anyways let me tell you about the problem I am having, hope you will answer me.... (6 Replies)
Discussion started by: majeed73
6 Replies

2. Shell Programming and Scripting

input redirection question

Hi, in my script I need to execute the following command: query $id 456 432 but it waits for a RETURN character from keyboard and therefore, it fails. I tried something like: query $id 456 432 << '\n' but, i'ts clear it is not correct. Is there any way to do this? Thxs. (0 Replies)
Discussion started by: luistid
0 Replies

3. Shell Programming and Scripting

Asking about shell script input output redirection

Hi, Can anyone please tell me what these lines do? ls >& outfile ls outfile 2>&1 Thanks. (1 Reply)
Discussion started by: trivektor
1 Replies

4. Shell Programming and Scripting

permanent redirection of standard input

while running a user inter-active program how can we get the commands from a file instead of the user? is there anyway to permanently redirect content of a file to standard input? (6 Replies)
Discussion started by: gfhgfnhhn
6 Replies

5. Shell Programming and Scripting

Input redirection and for loop

Hello, I need help with a bash script that I try to improve. I could not find answer so far, maybe because I'm not to familiar with the terminology so feel free to correct my language. I have a script that looks like: NODES="node_a node_b node_c" for NODE in $NODES do ... (4 Replies)
Discussion started by: pn8830
4 Replies

6. Shell Programming and Scripting

Read input and output redirection filename within a script

Hello everyone, My requirement is that within a script I need to construct the command line exactly that it was invoked with. For example : sh a.sh arg1 arg2 arg3 < input.txt > output.txt Now within a.sh, I construct a file which has these contents " sh a.sh arg1 arg2 arg3 < input.txt >... (8 Replies)
Discussion started by: hedonist12
8 Replies

7. Shell Programming and Scripting

How to check the user input to be valid using shell script?

How to check the user input to be valid using shell script? The valid input is in the format like as follows. 1. It can only have r,w,x or a hyphen and nothing else. 2. ensure the r, w, x are in the correct order. for example: rwxr-xr-x is a valid format. Thanks (5 Replies)
Discussion started by: hyeewang
5 Replies

8. UNIX for Dummies Questions & Answers

When do I use input redirection?

Can someone please explain when input redirection is necessary? For example, "cat filename" and "cat< filename" produce the same result. I was told that if I need to bunzip a file that I should type "bunzip2<filename.bz2." However, if I omit the "<" I still get the same result. Can someone... (4 Replies)
Discussion started by: PTcharger
4 Replies

9. Shell Programming and Scripting

Input redirection script

Hi, #!/bin/bash while ; do rm -f /tmp/pipe mkfifo /tmp/pipe ./yuv4mpeg_to_v4l2 < /tmp/pipe & mplayer tom_and_jerry.mp4 -vf scale=480:360 -vo yuv4mpeg:file=/tmp/pipe sleep 65; done When I run this - after mplayer finishes playing video it says - Exiting... (End of... (2 Replies)
Discussion started by: ashokvpp
2 Replies

10. Shell Programming and Scripting

Input redirection within bash script

Hi, when I try to redirect input and the command is described as a string within an array redirection does not work. why? #!/bin/bash dir=("tail < ./hello.txt") tail < ./hello.txt #works ${dir} #does not work (2 Replies)
Discussion started by: heinzel
2 Replies
isl(1M) 																   isl(1M)

NAME
isl - initial system loader DESCRIPTION
implements the operating system independent portion of the bootstrap process. It is loaded and executed after self-test and initialization have completed successfully. The processor contains special purpose memory for maintaining critical configuration related parameters (e.g. Primary Boot, Alternate Boot, and Console Paths). Two forms of memory are supported: Stable Storage and Non-Volatile Memory (NVM). Typically, when control is transferred to an sequence takes place. An sequence allows a complete bootstrap operation to occur with no intervention from an operator. executes commands from the file in a script-like fashion. is enabled by a flag in Stable Storage. is a mechanism that automatically locates the boot and console devices. For further information, see pdc(1M). During an sequence, displays its revision and the name of any utility it executes. However, if is disabled, after displays its revision, it then prompts for input from the console device. Acceptable input is any command name or the name of any utility available on the sys- tem. If a non-fatal error occurs or the executed utility returns, again prompts for input. Commands There are several commands available in although not all commads are supported on cellular systems . The following is a list with a short description. Parameters may be entered on the command line following the command name. They must be separated by spaces. prompts for any necessary parameters that are not entered on the command line. Help - List commands and available utilities List available utilities Enable or disable the autoboot sequence Parameter - or Enable or disable the sequence Parameter - or Modify the Primary Boot Path Parameter - Primary Boot Path in decimal Modify the Alternate Boot Path Parameter - Alternate Boot Path in decimal Modify the Console Path Parameter - Console Path in decimal List contents of the file Display the Primary Boot, Alternate Boot, and Console Paths Display the contents of one word of NVM in hexadecimal Parameter - NVM address in decimal or standard hexadecimal notation Display the contents of one word of Stable Storage in hexadecimal Parameter - Stable Storage address in decimal or standard hexadecimal notation DIAGNOSTICS
displays diagnostic information through error messages written on the console and display codes on the LED display. For the display codes, are informative only. and indicate errors, some of which are fatal and cause the system to halt. Other errors merely cause to display a message. Non-fatal errors during an sequence cause the sequence to be aborted and to prompt for input. After non-fatal errors during an interactive session, merely prompts for input. Fatal errors cause the system to halt. The problem must be corrected and the system RESET to recover. is executing. is from the file. Cannot find an file. aborted. No console found, can only Directory of utilities is too big, reads only 2K bytes. file is inconsistent. aborted. Utility file header inconsistent: SOM values invalid. file input string exceeds 2048 characters. aborted. command or utility name exceeds 10 characters. has transferred control to the utility. Internal inconsistency: Volume label - Internal inconsistency: Directory - Error reading file. Error reading from console - Error writing to console - Not an command or utility. Utility file header inconsistent: Invalid System ID. Error reading utility file header. Utility file header inconsistent: Bad magic number. Utility would overlay in memory. Utility requires more memory than is configured. Error reading utility into memory. Incorrect checksum: Reading utility into memory. Console needed - Internal inconsistency: Boot device class - Destination memory address of utility is invalid. Utility file header inconsistent: pdc_cache entry. Internal inconsistency: iodc_entry_init - Internal inconsistency: iodc_entry_init - console - Internal inconsistency: iodc_entry_init - boot device - Utility file header inconsistent: Bad aux_id. Bad utility file type. SEE ALSO
boot(1M), pdc(1M). PA-RISC Systems Only isl(1M)
All times are GMT -4. The time now is 10:54 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy