Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

c shell scripting, printf and fgrep

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
i am trying to print the values of variables given by user input to a file in the following format:

var1:var2:var3:::

with ":" as separators

my code is

echo -n "First Name: "
set name = $<
echo -n &quot;Last Name: &quot;
set last = $<

printf &quot;$name:$last::::&quot; >> .filename


///however the print the
var1:var2:var3::: will not print to the .filename in that format, it just prints the first word.

this code is trying to have a database of people
with that format...each new person with a new line

can anyone help??
 
neverming, this question has already been answered..thanks

jada20
 
Hi,
Just so everyone else knows the answer.

: is a special character in CSH variables. It allows operations on the variable.

csh
$x:h -- returns the directory portion of $x
$x:t -- returns the file name portion of $x
$x:e -- returns the file extension of $x
$x:r -- returns everything else (rest) but extension
$x:s/pat/pat2/ -- substitutes pat2 for pat in $x
$x:gs/pat/pat/ -- Does a global substitute in $x

There are several others but these are the main ones.

To get aroiund this issue put your variable name in {}

$var1:$var2:$var3 needs to be coded as ${var1}:${var2}:${var3}

if you want to use the : as a special operator the : goes inside the braces.

$x:h and ${x:h} are the same




 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top