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 7613083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:04:48+00:00 2026-05-31T02:04:48+00:00

In following shell, error shows LD_LIBRARY_PATH: unbound variable if the LD_LIBRARY_PATH not set. Can

  • 0

In following shell, error shows LD_LIBRARY_PATH: unbound variable if the LD_LIBRARY_PATH not set.

Can I use similar usage like ${xxx:-yyy} to simplified it.

#!/bin/bash
set -o nounset
export LD_LIBRARY_PATH=/mypath:$LD_LIBRARY_PATH
  • 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-31T02:04:49+00:00Added an answer on May 31, 2026 at 2:04 am

    You could use this construct:

    export LD_LIBRARY_PATH=/mypath${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
    

    Explanation:

    • If LD_LIBRARY_PATH is not set, then ${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} expands to nothing without evaluating $LD_LIBRARY_PATH, thus the result is equivalent to export LD_LIBRARY_PATH=/mypath and no error is raised.

    • If LD_LIBRARY_PATH is already set, then ${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} expands to :$LD_LIBRARY_PATH, thus the result is equivalent to export LD_LIBRARY_PATH=/mypath:$LD_LIBRARY_PATH.

    See the Bash Reference Manual / 3.5.3 Shell Parameter Expansion for more information on these expansions.

    This is an important security practice as two adjacent colons or a trailing/leading colon count as adding the current directory to $PATH or $LD_LIBRARY_PATH. See also:

    • What corner cases must we consider when parsing path on linux
    • bash: $PATH ending in colon puts working directory in PATH
    • How Torch broke ls
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following to execute shell commands using Node: function puts( error, stdout,
Can I embed the following bash shell code: for name in $(git diff --name-only
I am using the following code to call a batch file: dim shell set
I have the following shell script. For some reason the java program's standard error
Following the advice here I can get a shell script in JavaScript that runs
I have the following shell script : #!/bin/sh output=`./process_test.sh status_pid | grep NOT STARTED:
I have been trying to execute the following UNIX shell script which is not
In a shell script I wrote following lines gave error during execution of script
Would you please explain why the following shell command wouldn't work: sh-3.1$ echo $MYPATH
How do I convert the following shell commands in a chef recipe? Install sudo

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.