LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-27-2004, 07:01 AM   #1
Alan Lakin
Member
 
Registered: Sep 2002
Location: Wallington, Surrey, UK
Distribution: Ubuntu, Android phone
Posts: 119

Rep: Reputation: 15
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.
 
Old 02-27-2004, 09:23 AM   #2
sarin
Member
 
Registered: May 2001
Location: India, Kerala, Thrissur
Distribution: FC 7-10
Posts: 354
Blog Entries: 2

Rep: Reputation: 34
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
 
Old 02-27-2004, 02:41 PM   #3
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
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.
 
Old 02-27-2004, 02:59 PM   #4
Alan Lakin
Member
 
Registered: Sep 2002
Location: Wallington, Surrey, UK
Distribution: Ubuntu, Android phone
Posts: 119

Original Poster
Rep: Reputation: 15
Sarin, thanks for the tip.

I've just had a look for .xinitrc and I do not appear to have one 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

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.
 
Old 02-27-2004, 04:30 PM   #5
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
/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.

Last edited by slakmagik; 02-27-2004 at 04:32 PM.
 
Old 02-27-2004, 04:43 PM   #6
dford
Member
 
Registered: May 2003
Location: Kansas
Distribution: RH 9, OpenBSD, FreeBSD
Posts: 60

Rep: Reputation: 19
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.
 
Old 02-27-2004, 05:18 PM   #7
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
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.

Last edited by slakmagik; 02-27-2004 at 05:20 PM.
 
Old 02-27-2004, 05:21 PM   #8
Alan Lakin
Member
 
Registered: Sep 2002
Location: Wallington, Surrey, UK
Distribution: Ubuntu, Android phone
Posts: 119

Original Poster
Rep: Reputation: 15
/etc/X11/xinitrc/xinit? You mean /etc/X11/xinit/xinitrc?

Silly me

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

Thanks for the help
 
Old 03-11-2004, 10:14 AM   #9
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Bash: Check if a program is running naimslim89 Programming 12 05-08-2012 10:24 PM
Running two copy's of the same bash script AndiOliver Programming 2 10-06-2004 03:46 AM
bash scripts and running .sh files xviddivxoggmp3 Programming 9 08-14-2004 05:33 AM
Running bash scripts from C++ application bfkeats Programming 1 06-18-2003 05:44 PM
problems running c programs in bash KDE4me Programming 10 05-01-2003 12:22 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:06 PM.

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