LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 03-03-2021, 07:07 PM   #1
lancsuk
Member
 
Registered: Jul 2019
Location: Burnley / UK
Distribution: Slackware current
Posts: 226

Rep: Reputation: 204Reputation: 204Reputation: 204
My script does not work properly, what is wrong?


Hiya,

I was stuggling to install Xmonad on Slackware current, to me the best way to install Xmonad on Slackware current I think is stack.

I wrote a small script to make it easier to install and it works almost perfect.

Code:
#!/bin/bash
PRGNAM=xmonad
PRGNAM_HOME=$HOME/.$PRGNAM

LPATH=$HOME/.local/bin
CWD=$(pwd)

if [ ! -d $LPATH ]; then
	mkdir -p $LPATH
	echo 'export PATH=\$PATH:$LPATH >> $HOME/.bash_profile'
	source $HOME/.bash_profile
fi

wget -qO- https://get.haskellstack.org/ | sh

stack setup

mkdir -p $PRGNAM_HOME 
cd $PRGNAM_HOME 

# from inside of $PRGNAM_HOME/
git clone "https://github.com/xmonad/xmonad" xmonad-git
git clone "https://github.com/xmonad/xmonad-contrib" xmonad-contrib-git
git clone "https://github.com/jaor/xmobar" xmobar-git

stack init

mv $PRGNAM_HOME/stack.yaml $PRGNAM_HOME/stack.yaml.orig
cp $CWD/stack.yaml $PRGNAM_HOME/stack.yaml || exit 1

# from inside of $PRGNAM_HOME
stack install

cp $CWD/build $PRGNAM_HOME/build || exit 1

chmod a+x $PRGNAM_HOME/build

cp $CWD/xmonad.hs $PRGNAM_HOME/ || exit 1
cp $CWD/xmobarrc ~/.xmobarrc || exit 1
cp $CWD/xinitrc.xmonad ~/.xinitrc || exit 1
cp -a $CWD/wallpaper ~/wallpaper || exit 1
But the if then statement does not work properly in particular to source my .bash_profile file....

Code:
if [ ! -d $LPATH ]; then
	mkdir -p $LPATH
	echo 'export PATH=\$PATH:$LPATH >> $HOME/.bash_profile'
	source $HOME/.bash_profile
fi
....to source my bash_profile manually works great, but I prefer a 100% automatically installation.

any suggestions?


thanks Frank
 
Old 03-03-2021, 07:23 PM   #2
blancamolinos
Member
 
Registered: Mar 2011
Distribution: Slackware
Posts: 109

Rep: Reputation: 70
I think the mistake is in the single quotes.

echo 'export PATH=\$PATH:$LPATH >> $HOME/.bash_profile'

The echo command would be

echo 'export PATH=\$PATH:$LPATH' >> $HOME/.bash_profile

Last edited by blancamolinos; 03-03-2021 at 07:31 PM.
 
Old 03-03-2021, 08:00 PM   #3
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
You need also double quotes for variables interpolation
Code:
echo "export PATH=\$PATH:$LPATH" >> $HOME/.bash_profile
Code:
# from script
wget -qO- https://get.haskellstack.org/ | sh
Not sure I would be calm using this, website could be compromised

Last edited by keefaz; 03-03-2021 at 08:04 PM.
 
Old 03-03-2021, 08:07 PM   #4
Loomx
Member
 
Registered: Sep 2012
Distribution: Slackware
Posts: 184

Rep: Reputation: Disabled
Apart from the line the others have mentioned, you need to move the 'source $HOME/.bash_profile' line to after the end of the if statement (after the 'fi' line)
Otherwise it gets skipped if the ~/.local/bin directory exists.
 
Old 03-03-2021, 08:15 PM   #5
blancamolinos
Member
 
Registered: Mar 2011
Distribution: Slackware
Posts: 109

Rep: Reputation: 70
At first I also believed that it was necessary to change the single quotes to double quotes but then I hesitated since the source command should act in the same right way.

Last edited by blancamolinos; 03-03-2021 at 08:17 PM.
 
1 members found this post helpful.
Old 03-03-2021, 09:21 PM   #6
lancsuk
Member
 
Registered: Jul 2019
Location: Burnley / UK
Distribution: Slackware current
Posts: 226

Original Poster
Rep: Reputation: 204Reputation: 204Reputation: 204
Quote:
Originally Posted by keefaz View Post
You need also double quotes for variables interpolation
Code:
echo "export PATH=\$PATH:$LPATH" >> $HOME/.bash_profile
You are right, after I have changed my ~/.bash_profile looks great.

~/.bash_profile
Code:
export LANG=en_GB.UTF-8
export LC_COLLATE=C
export MESA_LOADER_DRIVER_OVERRIDE=i965

export PATH=/usr/local/bin:/usr/bin:/bin:/usr/games:/usr/lib64/kf5:/usr/lib64/kde4/libexec:/usr/lib64/qt5/bin:/home/lancs/.local/bin
But still I can't source my ~/.bash_profile by script, just manually.

Quote:
# from script
wget -qO- https://get.haskellstack.org/ | sh
[/code]
Not sure I would be calm using this, website could be compromised
Might be, but is actually the offical recommended way to install stack.

Last edited by lancsuk; 03-03-2021 at 09:46 PM.
 
Old 03-03-2021, 09:24 PM   #7
Loomx
Member
 
Registered: Sep 2012
Distribution: Slackware
Posts: 184

Rep: Reputation: Disabled
Did you move the "source ..." line to after the "fi" line?
 
Old 03-03-2021, 09:45 PM   #8
lancsuk
Member
 
Registered: Jul 2019
Location: Burnley / UK
Distribution: Slackware current
Posts: 226

Original Poster
Rep: Reputation: 204Reputation: 204Reputation: 204
Quote:
Originally Posted by Loomx View Post
Apart from the line the others have mentioned, you need to move the 'source $HOME/.bash_profile' line to after the end of the if statement (after the 'fi' line)
Otherwise it gets skipped if the ~/.local/bin directory exists.
Maybe I am wrong but my understanding was, when $HOME/local/bin exist, then the PATH to $HOME/.local/bin exist as well.

That is the reason why I created a

Code:
if [ ! -d directory ]; then
  mkdir directory
fi
 
Old 03-03-2021, 10:30 PM   #9
Loomx
Member
 
Registered: Sep 2012
Distribution: Slackware
Posts: 184

Rep: Reputation: Disabled
That is correct, but don't you want to source the ~/.bash_profile file regardless?

As it it written, the line "source ~/.bash_profile" is within the if statement. This means it only runs if the $LPATH directory *doesn't* exist.
 
Old 03-03-2021, 10:51 PM   #10
lancsuk
Member
 
Registered: Jul 2019
Location: Burnley / UK
Distribution: Slackware current
Posts: 226

Original Poster
Rep: Reputation: 204Reputation: 204Reputation: 204
Quote:
Originally Posted by Loomx View Post
That is correct, but don't you want to source the ~/.bash_profile file regardless?

As it it written, the line "source ~/.bash_profile" is within the if statement. This means it only runs if the $LPATH directory *doesn't* exist.
Not necessarily but still worth considering, but why does
Code:
source $HOME/.bash_profile
not work? Is a bit weird.
 
Old 03-03-2021, 11:14 PM   #11
Loomx
Member
 
Registered: Sep 2012
Distribution: Slackware
Posts: 184

Rep: Reputation: Disabled
I don't feel I'm explaining myself very well...

Quote:
Originally Posted by lancsuk View Post
... but why does
Code:
source $HOME/.bash_profile
not work? Is a bit weird.
Step by step:

1. "source $HOME/.bash_profile" runs if you enter it in a terminal, but doesn't in the script?

2. Does it still look like this in the script?:

Code:
if [ ! -d $LPATH ]; then
	mkdir -p $LPATH
	...
	source $HOME/.bash_profile
fi
 
Old 03-04-2021, 01:48 AM   #12
lancsuk
Member
 
Registered: Jul 2019
Location: Burnley / UK
Distribution: Slackware current
Posts: 226

Original Poster
Rep: Reputation: 204Reputation: 204Reputation: 204
Quote:
Originally Posted by Loomx View Post
I don't feel I'm explaining myself very well...



Step by step:

1. "source $HOME/.bash_profile" runs if you enter it in a terminal, but doesn't in the script?
1. exactly

Quote:
2. Does it still look like this in the script?:

Code:
if [ ! -d $LPATH ]; then
	mkdir -p $LPATH
	...
	source $HOME/.bash_profile
fi
2. Yes
 
Old 03-04-2021, 02:24 AM   #13
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,992

Rep: Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337
what I don't understand:
you do not need to put it into .bash_profile, you can do the following:
Code:
###### original
# if [ ! -d $LPATH ]; then
# 	mkdir -p $LPATH
# 	echo 'export PATH=\$PATH:$LPATH >> $HOME/.bash_profile'
# 	source $HOME/.bash_profile
# fi

##### new
mkdir -p $LPATH
export PATH=$PATH:$LPATH
Obviously you can put it into .bash_profile if you wish, but not really required for this script.
 
Old 03-04-2021, 02:35 AM   #14
Loomx
Member
 
Registered: Sep 2012
Distribution: Slackware
Posts: 184

Rep: Reputation: Disabled
That's what I thought.

This test
Code:
if [ ! -d $LPATH ]; then
tests if the $LPATH directory doesn't exist. If it succeeds (i.e. the directory doesn't exist) then it runs all the following commands until the
Code:
fi
line.

Assuming you do indeed have a directory $HOME/.local/bin then this test will fail and the following commands (including the "source ..." command) won't run.

If you move the "source ..." line after the "fi" line it won't be dependant on the test and will run every time the script runs.


@pan64 - well, yes, that would be a clean way to do it :-) But the OP had a specific question about why the "source ..." line wasn't running.
 
1 members found this post helpful.
Old 03-04-2021, 03:35 AM   #15
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,992

Rep: Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337
Quote:
Originally Posted by Loomx View Post
That's what I thought.

This test
Code:
if [ ! -d $LPATH ]; then
tests if the $LPATH directory doesn't exist. If it succeeds (i.e. the directory doesn't exist) then it runs all the following commands until the
Code:
fi
line.

Assuming you do indeed have a directory $HOME/.local/bin then this test will fail and the following commands (including the "source ..." command) won't run.

If you move the "source ..." line after the "fi" line it won't be dependant on the test and will run every time the script runs.


@pan64 - well, yes, that would be a clean way to do it :-) But the OP had a specific question about why the "source ..." line wasn't running.
that if construct is just wrong. It did not check if the entry (LPATH) was already added to .bash_profile, and also "sometimes" it won't be sourced. Not to speak about other problems (see shellcheck for example, or error handling)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP script does not work properly cucolin@ Linux - Server 14 08-03-2012 01:40 PM
Java does not work, I DLed Java and it still does not work M$ISBS Linux - Newbie 0 04-15-2007 08:20 PM
pci-e support: nvidia 6600gt not properly recognized? nvtv does not work... spad Linux - Hardware 1 09-26-2005 07:11 AM
firefox / kde: "open with"-menu does not work properly pit1516 Linux - Software 2 07-21-2005 04:01 PM
NVIDIA does not work properly in 10.1 Cornholio Slackware 7 03-28-2005 03:00 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 10:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration