Operating System - HP-UX
1748164 Members
3637 Online
108758 Solutions
New Discussion юеВ

want to assign dirname to variable... HP UX 11.23

 
SOLVED
Go to solution
John O'Neill_6
Regular Advisor

want to assign dirname to variable... HP UX 11.23

Hi All,

I've got some scripts provided by a consultant which are not working, some investigation reveals that the scripts are trying to assign the values of:

dirname
basename

to variables...but it's not working :(

Here's a small test script i made.

#!/bin/ksh
#test.sh
dbdir='dirname $1'
echo $dbdir

I pass the name of a file and i get this ...

# dirname $1

For some reason 'dirname $1' is not working and being treated as a literal.. yet every example I see of 'ksh' has this working.

Running HP UX 11.23 on Itanium, i've also tried this on HP UX 11.22 PA-Risc and no go there either...

Obviously I'm doing something dumb, but what??

Please help...

-John

8 REPLIES 8
John O'Neill_6
Regular Advisor

Re: want to assign dirname to variable... HP UX 11.23

Sorry, updated script, same issue however.

#!/usr/bin/ksh
#test.sh
dbdir='dirname $1'
echo $dbdir

Why does this not work? :(

:(

-John
Davis Paul
Valued Contributor
Solution

Re: want to assign dirname to variable... HP UX 11.23

Hi John
Make a modification as follows:

#!/bin/ksh
#test.sh
dbdir='dirname '$1
echo $dbdir

I found the problem with the line " dbdir='dirname $1' "

Thanks and regards,
Davis Paul.
Venkatesh BL
Honored Contributor

Re: want to assign dirname to variable... HP UX 11.23

Use "`" instead of "'"
Shrikant Lavhate
Esteemed Contributor

Re: want to assign dirname to variable... HP UX 11.23

yes. Its not sigle quote. use backquote. Shift and tild key above tab key.

Back quote is to execute shell var.
Will it remain a personal, if I broadcast it here!
John O'Neill_6
Regular Advisor

Re: want to assign dirname to variable... HP UX 11.23

Oh my goodness!!!! THANKYOU PEOPLE!!!

I had NO IDEA that was what the isse was...i've spent a 'whole day' on this damned thing, copying/pasting, retying from tutorials and so forth.

I'll now go back and look at these scripts... they were supplied in a PDF file and I copied/pasted them to notepad then put them onto the system.

I will make a note of this, to use:
` instead of '

:) Am now Happy :) Points assigned!
Patrick Wallek
Honored Contributor

Re: want to assign dirname to variable... HP UX 11.23

If you want to make it even easier, use the $() convention instead of the back-ticks, back-quotes (whatever you want to call them).

The $() convention is MUCH MUCH easier to read and will NEVER be mistaken for a single-quote.

dbdir=$(dirname $1)

John O'Neill_6
Regular Advisor

Re: want to assign dirname to variable... HP UX 11.23

Awesome Stuff! :)

thanks again everyone!

I've fixed the scripts and they work now!

Going to give that ($) a go tommorrow too

-John
Dennis Handly
Acclaimed Contributor

Re: want to assign dirname to variable... HP UX 11.23

>Going to give that $() a go tomorrow too

It's the best thing since sliced bread. You can nest $( ... $(...) ... )
You can throw away cat with: $(< file)
You can also get arithmetic expressions:
echo $(( 1 + 2 ))