Sponsored Content
Top Forums Shell Programming and Scripting Partial variable substitution in script Post 302930301 by anil510 on Friday 2nd of January 2015 04:09:18 AM
Old 01-02-2015
Partial variable substitution in script

I have a script.

Code:
filecreatenew ()  {
        touch /usr/src/$1_newfile.txt
        var=$1
        echo $var
        touch /usr/src/$var_newfile_with_var.txt
}

filecreatenew myfile

Its creating file /usr/src/myfile_newfile.txt as the variable $1 is correctly used. When $ is assigned to $var, the variable in $var is echoed fine, but the file is not getting created. How can I get the file myfile_newfile_with_var.txt correctly with the above script. ie the variable passed from $1 to $var should work in the line "touch /usr/src/$var_newfile_with_var.txt"
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Substitution in a variable

Hey All, I'm trying to clean up a variable using sed but It dosn't seem to work. I'm trying to find all the spaces and replace them with "\ " (a slash and a space). For Example "Hello World" should become "Hello\ World". But it does nothing. If I put it directly into the command line it works... (3 Replies)
Discussion started by: spragueg
3 Replies

2. UNIX for Dummies Questions & Answers

variable substitution

Hi everyone, I have a simple question to ask : In a script that I'm writting, I need to create variables on-the-fly. For instance, for every iterartion of the following loop a var_X variable should be generated : #!/bin/ksh a="1 2 3" for i in $a do var_${i}=$i echo "${var_$i}" done ... (1 Reply)
Discussion started by: ck-18
1 Replies

3. Shell Programming and Scripting

Sed variable substitution when variable constructed of a directory path

Hello, i have another sed question.. I'm trying to do variable substition with sed and i'm running into a problem. my var1 is a string constructed like this: filename1 filerev1 filepath1 my var2 is another string constructed like this: filename2 filerev2 filepath2 when i do... (2 Replies)
Discussion started by: alrinno
2 Replies

4. Shell Programming and Scripting

Variable Substitution

Hi , I have a variable as follows, Temp=`cat ABC.txt | cut -c5-` This will yeild a part of the date. say , 200912. I would like to substitute this variable's value in a filename. eg: File200912F.zip when i say File$TempF.zip , it is not substituting. Any help ? Thanks in... (2 Replies)
Discussion started by: mohanpadamata
2 Replies

5. Shell Programming and Scripting

Making script show command (e.g. copy) being executed and variable substitution?

When script is running you only see when some of the commands are not successfull. Is there a way to see which command are executed and to show the substitution of variables as every line is executed ? (3 Replies)
Discussion started by: gr0124
3 Replies

6. Shell Programming and Scripting

How to use variable with command substitution in variable

For example I have variable like below echo $OUTPUT /some/path/`uname -n` when I try to use the variable OUTPUT like below cd $OUTPUT or cd ${OUTPUT} I am getting bad substituion error message $ cd $OUTPUT ksh: cd: bad substitution $ cd ${OUTPUT} ksh: cd: bad substitution ... (1 Reply)
Discussion started by: rajukv
1 Replies

7. Shell Programming and Scripting

AWK - Print partial line/partial field

Hello, this is probably a simple request but I've been toying with it for a while. I have a large list of devices and commands that were run with a script, now I have lines such as: a-router-hostname-C#show ver I want to print everything up to (and excluding) the # and everything after it... (3 Replies)
Discussion started by: ippy98
3 Replies

8. Shell Programming and Scripting

awk syntax(partial) in variable

if a variable has part of awk syntax stored in it. for eg: x=if($1>100) can we substitute this variable in an awk statement. based on above requirement can we execute something like: awk '{x print $1}' infile (5 Replies)
Discussion started by: 47shailesh
5 Replies

9. Shell Programming and Scripting

sed variable substitution in a script

Hi I am trying to do the following in a script find a string and add in a block of text two lines above on the command line this works fine #/usr/bin/cat /usr/local/etc/dhcpd.conf_subnet | /usr/xpg4/bin/sed -n -e '1h;1\!H;${;g;s/}.*#END of 10.42.33.0/#START of RANGE $dstart\:option... (3 Replies)
Discussion started by: eeisken
3 Replies

10. Shell Programming and Scripting

Bash script having variable substitution problems

Hi I am setting the variables like this : setenv MODULE1 modem5__3 setenv MODULE2 modem5__2 setenv MODULE3 modem_ctrl_1_1 setenv MODULE4 modem_1_0 setenv COUNT 10 I am having a bash script as shown below ################################################ #!/bin/bash for ((... (5 Replies)
Discussion started by: kshitij
5 Replies
yppasswdd(8yp)															    yppasswdd(8yp)

Name
       yppasswdd - server daemon for modifying the yellow pages (YP) password file

Syntax
       /usr/etc/rpc.yppasswdd file [ -m arg1 arg2 ...  ]

Description
       The daemon is a server that handles password change requests from It changes a password entry in the specified file, which is assumed to be
       in the same format described in An entry in file will be changed only if the password presented by matches the encrypted password  of  that
       entry.

       If  the	option is given, then after file is modified, a will be performed in Any arguments following the flag will be passed to The option
       should be set only at a YP master server machine.

       This server is not run by default, nor can it be started up from If it is desired to enable remote password updating for the yellow  pages,
       then an entry for should be put in the file of the host serving as the master for the yellow pages file.

Examples
       If the yellow pages password file is stored as then to have password changes propagated immediately, the server should be invoked as:
       /usr/etc/rpc.yppasswdd /var/yp/src/passwd -m passwd DIR= /var/yp/src

Files
See Also
       yppasswd(1yp), passwd(5yp), ypfiles(5yp), ypmake(8yp)

																    yppasswdd(8yp)
All times are GMT -4. The time now is 03:53 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy