LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-21-2016, 12:00 PM   #1
jmgibson1981
Member
 
Registered: Jun 2015
Location: Tucson, AZ USA
Distribution: Ubuntu LTS
Posts: 185

Rep: Reputation: Disabled
Call part of case statement from KDE startup settings.


Using Kubuntu at the moment but works for any kde. I know how to set a script to run at startup or shutdown with the "Startup & Shutdown" in the system settings.

For better or for worse I like to keep a single master script separated by case statements for my general user tasks. How can I call a specific part of the script instead of just a plain small script. Basically how can I do this from the system settings section.

Code:
/home/jason/bin/myscript function
instead of only being able to do this...

Code:
/home/jason/bin/myscript
 
Old 03-21-2016, 02:10 PM   #2
hydrurga
Senior Member
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 18.2 MATE
Posts: 3,491
Blog Entries: 2

Rep: Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198
I'm not sure that you can, since KDE creates symlinks to do the job. Hopefully someone will prove me wrong.

You could always set up aliases in your shell configuration to myscripta, myscriptb, myscriptc etc., each indicating a different parameter to pass to the script.

Alternatively, you could call your master script and have it source/read its parameters from a file.
 
Old 03-21-2016, 03:08 PM   #3
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,714

Rep: Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280
use a symbolic link to the real script using the function name you want:


ln -s /home/jason/bin/myscript function

In the script startup use "$0" to get the path used to invoke the script, then use basename to
get just the function name. You can even use a hard link if you want - either way will work.

This has been used a LOT before. In the past, mv, ln, and even cp (back with SystemV mind) were all the same executable - just with different functions carried out based on the name.
 
1 members found this post helpful.
Old 03-21-2016, 03:50 PM   #4
hydrurga
Senior Member
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 18.2 MATE
Posts: 3,491
Blog Entries: 2

Rep: Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198
Quote:
Originally Posted by jpollard View Post
use a symbolic link to the real script using the function name you want:


ln -s /home/jason/bin/myscript function

In the script startup use "$0" to get the path used to invoke the script, then use basename to
get just the function name. You can even use a hard link if you want - either way will work.

This has been used a LOT before. In the past, mv, ln, and even cp (back with SystemV mind) were all the same executable - just with different functions carried out based on the name.
Beautiful. :-)
 
Old 03-22-2016, 04:02 PM   #5
normanlinux
Member
 
Registered: Apr 2013
Distribution: Arch and SuSE
Posts: 151

Rep: Reputation: Disabled
Quote:
Originally Posted by jpollard View Post
This has been used a LOT before. In the past, mv, ln, and even cp (back with SystemV mind) were all the same executable - just with different functions carried out based on the name.
Yes and it's a pity that - since we started using the BSD symbolic links - everybody has forgotten that. Despite all the emphasis on DRY (do'nt repeat yourself) we end up with several programs with just minor differences. (What's the difference between cp and mv? mv has an unlink at the end) $0 was so useful
 
Old 03-23-2016, 07:14 AM   #6
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,714

Rep: Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280
Well, it is still used a good bit. If you look at the lvm family (on my system in /usr/sbin)
you see:

Code:
1465620 lrwxrwxrwx. 1 root root            3 Jan 30  2015 vgcfgbackup -> lvm
1465152 lrwxrwxrwx. 1 root root            3 Jan 30  2015 vgcfgrestore -> lvm
1465079 lrwxrwxrwx. 1 root root            3 Jan 30  2015 vgchange -> lvm
1464918 lrwxrwxrwx. 1 root root            3 Jan 30  2015 vgck -> lvm
1464882 lrwxrwxrwx. 1 root root            3 Jan 30  2015 vgconvert -> lvm
1465457 lrwxrwxrwx. 1 root root            3 Jan 30  2015 vgcreate -> lvm
1465128 lrwxrwxrwx. 1 root root            3 Jan 30  2015 vgdisplay -> lvm
1465607 lrwxrwxrwx. 1 root root            3 Jan 30  2015 vgexport -> lvm
1465463 lrwxrwxrwx. 1 root root            3 Jan 30  2015 vgextend -> lvm
1465248 lrwxrwxrwx. 1 root root            3 Jan 30  2015 vgimport -> lvm
1465427 lrwxrwxrwx. 1 root root            3 Jan 30  2015 vgmerge -> lvm
1465195 lrwxrwxrwx. 1 root root            3 Jan 30  2015 vgmknodes -> lvm
1465296 lrwxrwxrwx. 1 root root            3 Jan 30  2015 vgreduce -> lvm
1465616 lrwxrwxrwx. 1 root root            3 Jan 30  2015 vgremove -> lvm
1465507 lrwxrwxrwx. 1 root root            3 Jan 30  2015 vgrename -> lvm
1464873 lrwxrwxrwx. 1 root root            3 Jan 30  2015 vgs -> lvm
1464907 lrwxrwxrwx. 1 root root            3 Jan 30  2015 vgscan -> lvm
1465380 lrwxrwxrwx. 1 root root            3 Jan 30  2015 vgsplit -> lvm
Here the symbolic links get used for the same thing. There are other programs as well - quotaoff is linked to quotaon, rdump linked to dump, the pvchange, pvck, pvcreate, pvdisplay, pvmove, pvremove, pvresize, pvs, and pvscan are also linked to lvm.

Not forgotten, just not advertised as much, and unfortunately, not taught in UNIX/Linux programming much. And I put that down to an overdependence on the GUI.
 
1 members found this post helpful.
Old 03-25-2016, 07:55 PM   #7
normanlinux
Member
 
Registered: Apr 2013
Distribution: Arch and SuSE
Posts: 151

Rep: Reputation: Disabled
Quote:
Originally Posted by jpollard View Post
Well, it is still used a good bit. If you look at the lvm family (on my system in /usr/sbin)
you see:

Code:
1465620 lrwxrwxrwx. 1 root root            3 Jan 30  2015 vgcfgbackup -> lvm
1465152 lrwxrwxrwx. 1 root root            3 Jan 30  2015 vgcfgrestore -> lvm
1465079 lrwxrwxrwx. 1 root root            3 Jan 30  2015 vgchange -> lvm
1464918 lrwxrwxrwx. 1 root root            3 Jan 30  2015 vgck -> lvm
1464882 lrwxrwxrwx. 1 root root            3 Jan 30  2015 vgconvert -> lvm
1465457 lrwxrwxrwx. 1 root root            3 Jan 30  2015 vgcreate -> lvm
1465128 lrwxrwxrwx. 1 root root            3 Jan 30  2015 vgdisplay -> lvm
1465607 lrwxrwxrwx. 1 root root            3 Jan 30  2015 vgexport -> lvm
1465463 lrwxrwxrwx. 1 root root            3 Jan 30  2015 vgextend -> lvm
1465248 lrwxrwxrwx. 1 root root            3 Jan 30  2015 vgimport -> lvm
1465427 lrwxrwxrwx. 1 root root            3 Jan 30  2015 vgmerge -> lvm
1465195 lrwxrwxrwx. 1 root root            3 Jan 30  2015 vgmknodes -> lvm
1465296 lrwxrwxrwx. 1 root root            3 Jan 30  2015 vgreduce -> lvm
1465616 lrwxrwxrwx. 1 root root            3 Jan 30  2015 vgremove -> lvm
1465507 lrwxrwxrwx. 1 root root            3 Jan 30  2015 vgrename -> lvm
1464873 lrwxrwxrwx. 1 root root            3 Jan 30  2015 vgs -> lvm
1464907 lrwxrwxrwx. 1 root root            3 Jan 30  2015 vgscan -> lvm
1465380 lrwxrwxrwx. 1 root root            3 Jan 30  2015 vgsplit -> lvm
Here the symbolic links get used for the same thing. There are other programs as well - quotaoff is linked to quotaon, rdump linked to dump, the pvchange, pvck, pvcreate, pvdisplay, pvmove, pvremove, pvresize, pvs, and pvscan are also linked to lvm.

Not forgotten, just not advertised as much, and unfortunately, not taught in UNIX/Linux programming much. And I put that down to an overdependence on the GUI.
Not quite the same. These are symbolic links - each taking an inode and requiring an extra disk access - whereas the old unix way was to use normal (now generally referred to as 'hard') links. These, of course, require no extra resources, simply being additional directory entries all pointing to the same inode
 
Old 03-26-2016, 06:41 AM   #8
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,714

Rep: Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280
It is still the same technique.

Hard links only work within one filesystem. Soft links work across file systems.

The name passed in $0 is still the one used to start the program/script.

Had soft links existed in early UNIX systems, hard links (other than the initial file creation) would not have been used.
 
Old 03-26-2016, 07:51 AM   #9
hydrurga
Senior Member
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 18.2 MATE
Posts: 3,491
Blog Entries: 2

Rep: Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198
Quote:
Originally Posted by jpollard View Post
It is still the same technique.

Hard links only work within one filesystem. Soft links work across file systems.

The name passed in $0 is still the one used to start the program/script.

Had soft links existed in early UNIX systems, hard links (other than the initial file creation) would not have been used.
Out of interest, why not? Hard links seem more intuitive for the task, at least to me, given their not needing to use an extra inode and therefore an extra lookup.
 
Old 03-26-2016, 09:02 AM   #10
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,714

Rep: Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280
Simple reason - symbolic links are more general than hard links. They are not tied to a specific filesystem and can point anywhere.

It also isn't even tied to executable. The $0 name is just the string specified to be used in the exec system call. It doesn't HAVE to even be the pathname to the executable, that is just a
convention. The string given is whatever the parent process specifies. Shells follow the convention that the string given is the name on the command line. HOW that name is given is up to the user/system. It isn't tied to hard links or soft links. Using either hard or soft links is just
a way to coerce the shell into using a specific string.
 
  


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
Perl switch statement throwing error like Bad case statement (invalid case value?) kavil Programming 2 10-07-2010 05:50 AM
LXer: The KDE 4.3 System Settings - Part 3 - Computer Administratio LXer Syndicated Linux News 0 02-09-2010 09:41 AM
LXer: The KDE 4.3 System Settings - Part 1 - Introduction + Look & Feel LXer Syndicated Linux News 0 02-03-2010 05:11 PM
Case statement with If statement cbo0485 Linux - Newbie 4 11-07-2007 09:05 PM
case statement baks Programming 2 03-15-2007 02:19 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:34 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration