Sponsored Content
Full Discussion: Shell variables problems
Top Forums Shell Programming and Scripting Shell variables problems Post 302356642 by cfajohnson on Saturday 26th of September 2009 02:21:44 PM
Old 09-26-2009
Quote:
Originally Posted by chipcmc
Thank you cfajohnson, the list of files does not contain blanks.
Normally I use :
Code:
while read line
do
....
done < file_list

i doesn't know UUOC's meaning, I it have looked in google and found other UUOC's cases that i doesn't know they are "bad code" or not optimus code.

At the least, an unnecessary cat is a waste of resources (cat is an external command, and therefore much slower than using shell syntax).

At the worst, it will fail. If you use later that script on another file that does have spaces in file names, it will fail. The redirection syntax will always work, giving you a more robust script.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

C Shell problems

I am a newbies here and also dummies in csh language. I've been told from my frenz this forum is very useful site for Q&A about UNIX script. Can anyone in here just lead me to learn more about csh language with code example. tq (3 Replies)
Discussion started by: unknown2205
3 Replies

2. UNIX for Dummies Questions & Answers

Problems with sed and flat file variables

Hello All, It has been a loooooooooooong time since I had last used sed but decided to use it for a simple task I have . My goal is to use sed to read variables from a flat file then use those same variables in order to make some subsitutions. However what I am finding is that when the... (1 Reply)
Discussion started by: icalderus
1 Replies

3. Shell Programming and Scripting

Shell script problems to do

Does anyone know a good site to do shell script problems? (0 Replies)
Discussion started by: cleansing_flame
0 Replies

4. Shell Programming and Scripting

problems calling out variables in a loop

good afternoon forums. i have a problem that ive been trying to work out all morning and cant seem to get my head around it. what i have in my script is individual letters saved in different variables. so if the word unix was saved then 'u' would be stored in the variable 'wvar1' 'n' in 'wvar2'... (7 Replies)
Discussion started by: strasner
7 Replies

5. UNIX for Dummies Questions & Answers

Problems in shell

hiiii this is the first time for me here >>> but really i have some problems for answers these things also understanding... Can any one help me? Write a simple shell as given in class. Your shell, called shell will read input lines from standard input, parse them into a... (3 Replies)
Discussion started by: Ronald kabbi
3 Replies

6. Shell Programming and Scripting

Problems with expect and set variables

I'm writing a script that'll send a time-stamp to my backup server. I create a file with the name of the current date, send it to my server with scp and rm the file from the local computer. Individually these commands work fine and with a set name the expect scripts also work fine. The problem... (0 Replies)
Discussion started by: Ktesh564
0 Replies

7. Shell Programming and Scripting

Two problems when I am writing my own shell

Hi, guys: I am writing my own shell using c. I meet with two problems. First, when I use tcsetpgrp system call to move a background job to foreground, when this job finishes, my shell program also exit. What is the problem for that? Second, when I use signal , if the child has its own... (1 Reply)
Discussion started by: tomlee
1 Replies

8. Shell Programming and Scripting

Problems with variables syntax

Hi there I am really struggling :eek: to place a value in a variable with the following loop, having run out of ideas please can someone point me in the right direction? We first read two PIDs of a program (say calc) into an array, then we loop reading the details of those processes into a... (6 Replies)
Discussion started by: nathan.harris
6 Replies

9. Shell Programming and Scripting

Problems with substitution between two variables

To all geeks, What I want to achieve: 1. Accept two filenames from user and store the filenames in two variables (FILE1 and FILE2) 2. Check if files exisits. If doesn't, then exit 3. If files exist, look for a particular string in both files 4. If the string exists, then change the... (8 Replies)
Discussion started by: Deepak Tulsani
8 Replies

10. Shell Programming and Scripting

Problems with awk (fatal error) and paste (two variables into one column-by-column)

Hello, I have a script extracting columns of useful numbers from a data file, and manipulating the numbers with awk commands. I have problems with my script... 1. There are two lines assigning numbers to $BaseForAveraging. If I use the commented line (the first one) and let the second one... (9 Replies)
Discussion started by: vgbraymond
9 Replies
SHELL-QUOTE(1)						User Contributed Perl Documentation					    SHELL-QUOTE(1)

NAME
shell-quote - quote arguments for safe use, unmodified in a shell command SYNOPSIS
shell-quote [switch]... arg... DESCRIPTION
shell-quote lets you pass arbitrary strings through the shell so that they won't be changed by the shell. This lets you process commands or files with embedded white space or shell globbing characters safely. Here are a few examples. EXAMPLES
ssh preserving args When running a remote command with ssh, ssh doesn't preserve the separate arguments it receives. It just joins them with spaces and passes them to "$SHELL -c". This doesn't work as intended: ssh host touch 'hi there' # fails It creates 2 files, hi and there. Instead, do this: cmd=`shell-quote touch 'hi there'` ssh host "$cmd" This gives you just 1 file, hi there. process find output It's not ordinarily possible to process an arbitrary list of files output by find with a shell script. Anything you put in $IFS to split up the output could legitimately be in a file's name. Here's how you can do it using shell-quote: eval set -- `find -type f -print0 | xargs -0 shell-quote --` debug shell scripts shell-quote is better than echo for debugging shell scripts. debug() { [ -z "$debug" ] || shell-quote "debug:" "$@" } With echo you can't tell the difference between "debug 'foo bar'" and "debug foo bar", but with shell-quote you can. save a command for later shell-quote can be used to build up a shell command to run later. Say you want the user to be able to give you switches for a command you're going to run. If you don't want the switches to be re-evaluated by the shell (which is usually a good idea, else there are things the user can't pass through), you can do something like this: user_switches= while [ $# != 0 ] do case x$1 in x--pass-through) [ $# -gt 1 ] || die "need an argument for $1" user_switches="$user_switches "`shell-quote -- "$2"` shift;; # process other switches esac shift done # later eval "shell-quote some-command $user_switches my args" OPTIONS
--debug Turn debugging on. --help Show the usage message and die. --version Show the version number and exit. AVAILABILITY
The code is licensed under the GNU GPL. Check http://www.argon.org/~roderick/ or CPAN for updated versions. AUTHOR
Roderick Schertler <roderick@argon.org> perl v5.16.3 2010-06-11 SHELL-QUOTE(1)
All times are GMT -4. The time now is 03:55 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy