Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 865337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:37:33+00:00 2026-05-15T09:37:33+00:00

I wish to source a script, print the value of a variable this script

  • 0

I wish to source a script, print the value of a variable this script defines, and then have this value be assigned to a variable on the command line with command substitution wrapping the source/print commands. This works on ksh88 but not on ksh93 and I am wondering why.

$ cat typeset_err.ksh
#!/bin/ksh
unset _typeset_var
typeset -i -r _typeset_var=1
DIR=init # this is the variable I want to print

When run on ksh88 (in this case, an AIX 6.1 box), the output is as follows:

$ A=$(. ./typeset_err.ksh; print $DIR)
$ echo $A
init

When run on ksh93 (in this case, a Linux machine), the output is as follows:

$ A=$(. ./typeset_err.ksh; print $DIR)
-ksh: _typeset_var: is read only
$ print $A

($A is undefined)

The above is just an example script. The actual thing I wish to accomplish is to source a script that sets values to many variables, so that I can print just one of its values, e.g. $DIR, and have $A equal that value. I do not know in advance the value of $DIR, but I need to copy files to $DIR during execution of a different batch script. Therefore the idea I had was to source the script in order to define its variables, print the one I wanted, then have that print’s output be assigned to another variable via $(...) syntax. Admittedly a bit of a hack, but I don’t want to source the entire sub-script in the batch script’s environment because I only need one of its variables.

The typeset -r code in the beginning is the error. The script I’m sourcing contains this in order to provide a semaphore of sorts–to prevent the script from being sourced more than once in the environment. (There is an if statement in the real script that checks for _typeset_var = 1, and exits if it is already set.) So I know I can take this out and get $DIR to print fine, but the constraints of the problem include keeping the typeset -i -r.

In the example script I put an unset in first, to ensure _typeset_var isn’t already defined. By the way I do know that it is not possible to unset a typeset -r variable, according to ksh93’s man page for ksh.

There are ways to code around this error. The favorite now is to not use typeset, but just set the semaphore without typeset (e.g. _typeset_var=1), but the error with the code as-is remains as a curiosity to me, and I want to see if anyone can explain why this is happening.

By the way, another idea I abandoned was to grep the variable I need out of its containing script, then print that one variable for $A to be set to; however, the variable ($DIR in the example above) might be set to another variable’s value (e.g. DIR=$dom/init), and that other variable might be defined earlier in the script; therefore, I need to source the entire script to make sure I all variables are defined so that $DIR is correctly defined when sourcing.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T09:37:33+00:00Added an answer on May 15, 2026 at 9:37 am

    It works fine for me in ksh93 (Version JM 93t+ 2009-05-01). If I do this, though:

    $ . ./typeset_err.ksh
    $ A=$(. ./typeset_err.ksh; print $DIR)
    -ksh: _typeset_var: is read only
    

    So it may be that you’re getting that variable typeset -r in the current environment somehow.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 505k
  • Answers 505k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Here is a simple expose: http://developers.facebook.com/docs/guides/web Here is the full… May 16, 2026 at 3:31 pm
  • Editorial Team
    Editorial Team added an answer If you want to understand BDD better, try thinking about… May 16, 2026 at 3:30 pm
  • Editorial Team
    Editorial Team added an answer I agree with the comment above recommending the use of… May 16, 2026 at 3:30 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I wish to make a self contained LAMP distro software package from source with
I'm having a website with many big images file. The source (as well as
EDIT: Thanks guys - perfect! I wish I could check more than one answer,
I am trying to write a LotusScript to control a motor. The script I
I've a jsp page which saves a request parameter inside a javascript variable. Say
I've been trying to learn this myself several hours and just had to give
I have a make file of, more or less, the following structure that compiles
I want to debug TCP/IP interactions for a program I'm enhancing. I don't have
I wish to develop a sms application in C#.net. So please help me by
I wish to a check if a method exists in an interface based on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.