LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   bash - running before I can walk! (https://www.linuxquestions.org/questions/programming-9/bash-running-before-i-can-walk-151108/)

Alan Lakin 02-27-2004 07:01 AM

bash - running before I can walk!
 
From time to time I have the urge to improve my very basic scripting skills. On this occassion I decided to try to pass an argument to startx to allow me to select a window manager of my choice. What I actually did was place a case statement at the end of /etc/X11/xinitrc/xinitrc. The idea being that I could say, startx xfce or startx kde. The resultant error message was along the lines of "xfce is an invalid argument". On the face of it I do not understand why I shouldn't pass an argument to the script if I have made provision to pick it up (the case statement).

I am simply currious to understand where I am going wrong.

Thanks.

sarin 02-27-2004 09:23 AM

I don't know where you are going wrong. But the simplest solution I can think of is this script. I haven't tested it since I don't have access to a proper linux m/c now ( Its been the case for about past one year :( ). SO this is what I think will be a solution to your problem.
Put this as a small script to your ~/bin or something that is there in your pat and make it executable. (Warning: This will destroy your current .xinitrc)

echo $1 > ~/.xinitrc
startx

and if the name of the script is sx do
sx gnome-session
sx startkde
etc to start the corresponding desktops

Hope this helps.

--Sarin

slakmagik 02-27-2004 02:41 PM

I so know what you mean about the run/walk thing. I try to run and can't even crawl.

Anyway, I believe XFCE is actually invoked with 'startxfce' or something rather than 'xfce'. That might be it. (The drive that had xfce on it croaked, so I dunno.) If you have a problem with a script, it always helps to post the script. :)

Like sarin says, that'll wipe the whole file. Maybe something like
Code:

sed s/^exec\.*/"exec $1"/ ~/.xintrc > .xinitrc.tmp
mv ~.xintrc ~.xinitrc.bak
mv ~/.xinitrc.tmp ~/.xinitrc

Kinda ugly but it'll preserve the rest of the file. I think.

Alan Lakin 02-27-2004 02:59 PM

Sarin, thanks for the tip.

I've just had a look for .xinitrc and I do not appear to have one :eek: I am not sure therefore what effect your script will have on my system.

digiot, your moving stuff around idea was something I was thinking about but then thought about the case statement in the REAL file. Your option is safer.

The curiosity gets worse - both solutions revolve around ~/.xinitrc but I DON'T HAVE ONE :confused:

What I actually tried was:

/etc/X11/xinitrc/xinit

-------------------------------------------------------------------------------------
#!/bin/sh
# $XConsortium: xinitrc.cpp,v 1.4 91/08/22 11:41:34 rws Exp $

userresources=$HOME/.Xresources
usermodmap=$HOME/.Xmodmap
sysresources=/usr/X11R6/lib/X11/xinit/.Xresources
sysmodmap=/usr/X11R6/lib/X11/xinit/.Xmodmap

# merge in defaults and keymaps

if [ -f $sysresources ]; then
xrdb -merge $sysresources
fi

if [ -f $sysmodmap ]; then
xmodmap $sysmodmap
fi

if [ -f $userresources ]; then
xrdb -merge $userresources
fi

if [ -f $usermodmap ]; then
xmodmap $usermodmap
fi

# Start the window manager:

case $1 in
xfce)
startxfce4
exit 0
;;
*)
startkde
exit 0
;;
esac

---------------------------------------------------------------------------------

I added the #Start the window manager bit. The standard script just calls THE window manager. I just wanted to build in choice rather than having to edit the file every time I wanted to use a different window manager to the rest of the family.

slakmagik 02-27-2004 04:30 PM

/etc/X11/xinitrc/xinit? You mean /etc/X11/xinit/xinitrc?

Well, copy that as ~/.xinitrc and you'll have an ~/.xinitrc. That looks like it should work, though. The only thing I can think of (and I think I experienced this before) is that 'startx' is a wrapper and pases arguments to xinit in a strange way. Trying to pass variables from bash to xinitrc to startx to xinit gets screwed up. You type 'xfce' meaning to case 'startxfce4' but it just passes 'xfce' to xinit. Or something. Basically, typing 'startx xfce' is a 'clientarg' parsed into an argument for 'client' (by startx) on the xinit command line, which doesn't work.

That's why I use separate stuff to feed the variable directly in the file - command line > myscript > ~/.xinitrc works. command line > ~.xinitrc doesn't.

But Slack has an 'xwmconfig' and I made a really simple version because I felt like it. So do something like use xwmconfig or an ~/.xinitrc edit or a symlink script, maybe.

dford 02-27-2004 04:43 PM

Quote:

case $1 in
xfce)
startxfce4
exit 0
;;
*)
startkde
exit 0
;;
esac

Try
case $1 in
(xfce)
startxfce4
exit 0
;;
(*)
startkde
exit 0
;;
esac


Also, /bin/sh doesn't have case. Although /bin/sh may be /bin/bash really. Just make sure.

slakmagik 02-27-2004 05:18 PM

Nah, his syntax was right - I'm pretty sure it's just startx getting in the way. Good point about sh, though. I didn't think about that. I still don't think it'll work, but it's worth a shot.

-- Oh. sh is almost certainly a symlink to bash but it still matters as to what bash acts like. When called as sh it tries to act like sh.

Alan Lakin 02-27-2004 05:21 PM

/etc/X11/xinitrc/xinit? You mean /etc/X11/xinit/xinitrc?

Silly me :o

I have not looked at xwmconfig. Perhaps that is the solution.

Thanks for the help :)

bigearsbilly 03-11-2004 10:14 AM

What is the 'exec' line of the startx script? (near the end)


TRy This:
if you have wmlist:
it will let you select from a list of installed managers


select wm in $(wmlist);do
export WINDOWMANAGER=$wm # maybe this ?
startx $wm & # or this
break
done;

it all depends how your particular startx script
calls the manager.

billy


All times are GMT -5. The time now is 12:58 AM.