10-13-2019
Shells don't expand variables within single quotes.
These 2 Users Gave Thanks to RudiC For This Post:
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I have a little script to help me manage a gallery of image files. It makes symbolic links to every file in and below the current directory, placing them in a target directory which is passed to the script as a parameter. Unfortunately, the script pukes when I pass a parameter that contains... (4 Replies)
Discussion started by: TanRanger
4 Replies
2. Shell Programming and Scripting
Hi all,
Can you please suggest a few lines of if statement to check if a variable is an ip address purely in bash/sh?
Thanks,
Marc (3 Replies)
Discussion started by: marcpascual
3 Replies
3. UNIX for Dummies Questions & Answers
I'm having problems with bash scripts. If a bash script is called with no arguments, I always get "PHIST=!" as the first argument (i.e. this is what $1 equals). Why? Where does this come from, and how can I fix it? Nothing in the bash man pages refer to this mysterious default argument. (2 Replies)
Discussion started by: sszd
2 Replies
4. Shell Programming and Scripting
Can someone please help me with this SHELL script?
I need to create a script that gets a positive number n as an argument. The script must calculate the factorial of its argument. In other words, it must calculate n!=1x2x3x...xn. Note that 0!=1.
Here is a start but I have no clue how to... (3 Replies)
Discussion started by: I-1
3 Replies
5. UNIX for Dummies Questions & Answers
Hi,
The following code finds the line containing fruits in test.txt and replaces instances of apple with banana.
ed -s test.txt <<< $'/fruits/s/apple/banana/g\nw'
What I want to do is put variables in the place of fruits, apple and banana.
I have tried replacing ' with " to get... (2 Replies)
Discussion started by: de_la_espada
2 Replies
6. Shell Programming and Scripting
Hi guys!
So, I use GET ( Simple user agent using LWP library. ) on a remote text file that is then passed to bash and executed. However, I need to pass that bash script a single argument, and so far nothing that I have tried has worked, although I have learned quite a bit about input/output... (5 Replies)
Discussion started by: Rhije
5 Replies
7. Shell Programming and Scripting
Hi everybody!
I am writing a script which accepts two arguments one of them being a message. All is working except for the message part. That is, to accept text as an argument.
I have trouble storing and echoing a line of text. It seems that writing a few words and store them in an... (6 Replies)
Discussion started by: bluetxxth
6 Replies
8. Shell Programming and Scripting
Hi Guys,
I have an issue with awk and variables. I have trawled the internet and forums but can't seem to get the exactt syntax I need.
I have tried using awk -v and all sorts of variations but I have hit a brick wall. I have spent a full day on this and am just going round in circles.
... (3 Replies)
Discussion started by: gazza-o
3 Replies
9. Shell Programming and Scripting
I have a bash script where I pass an argument
./chris.bash "\argv Test"
I want to detect if the user supplied \argv at the start of the argument (3 Replies)
Discussion started by: kristinu
3 Replies
10. UNIX for Beginners Questions & Answers
Hi Guys,
I wrote a collection of bash functions years ago and now need to use them again but
I'm getting some error messages when eval tries to expand the variables names.
I recollect that I used the shopt command to set one of the options but I can't quite
remember the command that I... (8 Replies)
Discussion started by: ASGR
8 Replies
LEARN ABOUT DEBIAN
strvars
STRVARS(3pub) C Programmer's Manual STRVARS(3pub)
NAME
strvars - expand variables in string
SYNOPSIS
#include <publib.h>
int strvars(char **res, const char *str, char *(*expand)(const char *));
DESCRIPTION
strvars will replaces references to variables in the string str with the values of the variables. A reference to a variable is of the form
$(foo) or $x (where x is a single character, but not $). A dollar sign is expressed in the string as $$, and will be converted to $ in the
output. Memory for the expanded string is allocated dynamically, and *res is set to point to it.
The values of the variables are fetched using the function expand. It is given the name of the variable as its argument, and must return a
pointer to the value, or NULL if that variable doesn't exist.
RETURN VALUE
strvars will return 0 if successful, or NULL if an error occured (malformed input string, result too big, or unknown variable).
EXAMPLE
To replace references to environment variables, one would the following.
#include <publib.h>
#include <stdlib.h>
char line[1024];
char *res;
if (strvars(&res, line, getenv) == NULL)
errormsg(1, 0, "strvars failed");
printf("res = <%s>
", res);
SEE ALSO
publib(3), getenv(3)
AUTHOR
Lars Wirzenius (lars.wirzenius@helsinki.fi)
Publib C Programmer's Manual STRVARS(3pub)