?
Solved

Making bash script from bash script

Posted on 2003-12-02
6
Medium Priority
?
818 Views
Last Modified: 2010-04-22
Dear experts.

I'm having problem making a bash script from another bash script.

The script I want to make is:
======================
#!/bin/sh
if [ ! -x "/opt/kde/bin/startkde" ]; then
   export PATH="$PATH:$opt/kde/bin"
fi
======================

The script that make that script is
======================
#!/bin/sh

# set the variables
PREFIX=/opt/kde  
SCRIPT=/etc/profile.d/kde.sh

# make the script
echo "#!/bin/sh" > $SCRIPT
echo "if [ ! -x \"$PREFIX/bin/startkde\" ]; then" >> $SCRIPT
echo "     export PATH=\"$PATH:$PREFIX/bin\"" >> $SCRIPT
echo "fi" >> $SCRIPT
======================

The result I got was not right, since the $PATH is always expanded to the env variables.
How to prefent it ?


Thanks.


0
Comment
Question by:Kocil
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9864588
use single quotes for quoting your script ...
$ gets expanded in double quotes but not single quotes
0
 
LVL 45

Assisted Solution

by:sunnycoder
sunnycoder earned 300 total points
ID: 9864608
#!/bin/sh

# set the variables
PREFIX=/opt/kde  
SCRIPT=/etc/profile.d/kde.sh

# make the script
echo '#!/bin/sh' > $SCRIPT
echo 'if [ ! -x \"$PREFIX/bin/startkde\" ]; then' >> $SCRIPT
echo '     export PATH=\"$PATH:$PREFIX/bin\"' >> $SCRIPT
echo 'fi' >> $SCRIPT
0
 
LVL 7

Accepted Solution

by:
glassd earned 500 total points
ID: 9865032
If you are using Bash then you can make the whole thing a bit neater.

{
echo '#!/bin/sh'
echo 'if [ ! -x \"$PREFIX/bin/startkde\" ]; then'
echo '     export PATH=\"$PATH:$PREFIX/bin\"'
echo 'fi'
} > $SCRIPT

or:

echo '#!/bin/sh
if [ ! -x \"$PREFIX/bin/startkde\" ]; then
     export PATH=\"$PATH:$PREFIX/bin\"
fi' > $SCRIPT

The first method allows you to include any command output, not just that from the "echo" command.
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 5

Author Comment

by:Kocil
ID: 9865156
Dear sunny.
The output from your script was

#!/bin/sh
if [ ! -x \"$PREFIX/bin/startkde\" ]; then
     export PATH=\"$PATH:$PREFIX/bin\"
fi

But i think I got the idea.
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9865194
Oh ... just noticed what you wanted is slightly different

#!/bin/sh

# set the variables
SCRIPT=/etc/profile.d/kde.sh

# make the script
echo '#!/bin/sh' > $SCRIPT
echo 'PREFIX=/opt/kde' >> $SCRIPT
echo 'if [ ! -x \"$PREFIX/bin/startkde\" ]; then' >> $SCRIPT
echo '     export PATH=\"$PATH:$PREFIX/bin\"' >> $SCRIPT
echo 'fi' >> $SCRIPT
0
 
LVL 5

Author Comment

by:Kocil
ID: 9865216
Glassd, unfortunatelly my script is for a slack package,
so I have to use the spec (sh / ash).

But this seems to works for me

# make the script
echo '#!/bin/sh
if [ ! -x startkde ]; then
    export PATH="$PATH:$PREFIX/bin"
fi' > $SCRIPT

Thanks for both of you.

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month13 days, 11 hours left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question