Sponsored Content
Full Discussion: A difficult script (for me)
Top Forums Shell Programming and Scripting A difficult script (for me) Post 302156168 by gus2000 on Monday 7th of January 2008 12:46:40 PM
Old 01-07-2008
First, you won't get variable substitution inside single-quotes:

Code:
# x=123
# echo 'x=$x'       # string is literal
x=$x

# echo "x=$x"       # string is evaluated by the shell
x=123

# echo "x='$x'"
x='123'

Single-quotes lose their special quoting superpowers when inside double-quotes.

Also, if you pass a string to a command that includes a dash ("-") you run the risk of the string being interpreted as flags. You should therefore use the double-dash to indicate that no more flags are coming:

Code:
grep -c -v -- "$string" $file

So if "$string" includes any dashes, they will be ignored since they are after the "--".
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Difficult Filtering Problem

Sir, I have a file containing say 1000 lines that contain 100 paragraphs of 10 lines each separated by blank lines.I have to match a pattern or a string "hdfhasdjkasdhs" and print the complete paragraphs containing these strings.I can do this with the help of line editor ex,but how can I use... (1 Reply)
Discussion started by: Piyush
1 Replies

2. Solaris

difficult time differences

:rolleyes: Hi, How to take the time diffence between start and finish time from a log file? It is like ..... started at Jun 20 23:20 . . ..... finished at Jun 21 01:40 Tryed so many ways but failed to ger exact way. :confused: Your help will be honoured. Ta........Lokesha (1 Reply)
Discussion started by: Lokesha
1 Replies

3. UNIX for Advanced & Expert Users

difficult sed command

Im trying to replace every line line1 line2 line3 with: line1 extraline1 line2 extraline2 line3 extraline3 with about 10 extra lines I am able to add axtra lines with: (17 Replies)
Discussion started by: Dave724001
17 Replies

4. UNIX for Dummies Questions & Answers

so difficult question about using grep

en...how to grep some words from some file, the goal is that, we donot want the words are exactly 9 charactor, and want to grep from some words that are longer than 9 and it contain a substring that with 9 different charactors (2 Replies)
Discussion started by: shrimpy
2 Replies

5. Shell Programming and Scripting

difficult nawk to understand

I found a command who prints x lines before and after a line who contain a searched string in a text file. The command is : nawk 'c-->0;$0~s{if(b)for(c=b+1;c>1;c--)print r;print;c=a}b{r=$0}' b=2 a=4 s="string" file1 It works very well but I can't understand the syntax, too difficult with... (2 Replies)
Discussion started by: ahmad.diab
2 Replies

6. Shell Programming and Scripting

Difficult problem: Complex text file manipulation in bash script.

I don't know if this is a big issue or not, but I'm having difficulties. I apoligize for the upcoming essay :o. I'm writing a script, similar to a paint program that edits images, but in the form of ANSI block characters. The program so far is working. I managed to save the image into a file,... (14 Replies)
Discussion started by: tinman47
14 Replies

7. Shell Programming and Scripting

Shell script menu for end user - difficult challenge

Hello, I need to make shell script menu for my end users. There is like 100 scripts in system, and they need to run that scripts true one main script with user friendly menu. Example, when user will run main menu script, it will get something like this on his screen:... (3 Replies)
Discussion started by: waso
3 Replies

8. Programming

Difficult in analyzing an algorithm

Hello, I was reading Heuritics text and came across an algorithm below. Finding hard to analyze it can any one help me out below... How to analyze if I take say no. of types are 5 and each type has say 20 coins. thanks. Let {c1, c2...cn=1} be a set of distinct coin types where ci is... (1 Reply)
Discussion started by: sureshcisco
1 Replies

9. Shell Programming and Scripting

Shell script menu for end user - difficult challenge 2

Hello, I need to make shell script menu for my end users. There is like 100 scripts in system, and they need to run that scripts true one main script with user friendly menu. Example, when user will run main menu script, it will get something like this on his screen:... (1 Reply)
Discussion started by: waso
1 Replies

10. Shell Programming and Scripting

Been working since 25+ hrs: Bash Script to rename files supposedly direct but difficult to execute

:wall::wall::wall: Hi I have horrible script below, need help in renaming ls -l output into new filename format: Desired output: cp -pv original_path/.* newDirectory/owner_of_file.%dd%mm%y.file_extension.first_8_characters_of_original_filename localuser@localuser:~ vi... (3 Replies)
Discussion started by: wolf@=NK
3 Replies
Tcl_AllowExceptions(3)					      Tcl Library Procedures					    Tcl_AllowExceptions(3)

__________________________________________________________________________________________________________________________________________________

NAME
Tcl_AllowExceptions - allow all exceptions in next script evaluation SYNOPSIS
#include <tcl.h> Tcl_AllowExceptions(interp) ARGUMENTS
Tcl_Interp *interp (in) Interpreter in which script will be evaluated. _________________________________________________________________ DESCRIPTION
If a script is evaluated at top-level (i.e. no other scripts are pending evaluation when the script is invoked), and if the script termi- nates with a completion code other than TCL_OK, TCL_ERROR or TCL_RETURN, then Tcl normally converts this into a TCL_ERROR return with an appropriate message. The particular script evaluation procedures of Tcl that act in the manner are Tcl_EvalObjEx, Tcl_EvalObjv, Tcl_Eval, Tcl_EvalEx, Tcl_GlobalEval, Tcl_GlobalEvalObj, Tcl_VarEval and Tcl_VarEvalVA. However, if Tcl_AllowExceptions is invoked immediately before calling one of those a procedures, then arbitrary completion codes are per- mitted from the script, and they are returned without modification. This is useful in cases where the caller can deal with exceptions such as TCL_BREAK or TCL_CONTINUE in a meaningful way. KEYWORDS
continue, break, exception, interpreter Tcl 7.4 Tcl_AllowExceptions(3)
All times are GMT -4. The time now is 11:28 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy