Sponsored Content
Full Discussion: Shell script with arguments
Top Forums Shell Programming and Scripting Shell script with arguments Post 45471 by zazzybob on Monday 22nd of December 2003 08:21:09 AM
Old 12-22-2003
Hello.

In this situation, I probably wouldn't even bother with getopts.

If you only want to install 1, 2, or 3 packages (thus assuming that the ONLY action that the script is to perform is to install packages) you could do the following:

Code:
#!/bin/sh

if [ "$#" -gt 3 ]; then
  echo "More than 3 arguments entered" && exit 1
fi

pkgs=""

if [ "$#" -eq 0 ]; then
  echo "Please enter a space seperated list of packages"
  read pkgs
fi

if [ -z "$pkgs" ]; then
  # user must have supplied some arguments
  for file in "$@"
  do
    # then install $file as you want
  done
else
  for file in "$pkgs"
  do
   # then install $file as you want
  done
fi

exit 0

Now... I haven't checked this out - just wrote it on the fly. But you get the idea......
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Is there a limit to the no. of arguments to a shell script ?

What is the maximum no. of arguments that could be passed to a shell script ? Is there any restriction ? I've a requirement where I need to pass a list of names to a unix script and I guess the number of such names is not a fixed one. It can run into hundreds. Is this feasible ? (4 Replies)
Discussion started by: hidnana
4 Replies

2. Shell Programming and Scripting

Need help to pass arguments to shell script

Hi, I have a shell script called ftp.sh which is running continously in background. I tried passing arguments to this script but it did not worked out. Below is ftp.sh script. Please help me case $param in start) sleep_func "300" echo "!ksh $scr_ddir/ftp.sh... (1 Reply)
Discussion started by: bhargav20
1 Replies

3. Shell Programming and Scripting

no of arguments to function in shell script

Hi, I have a function in shell script fun1{ echo "No.of arguments are..."} this function will be called in same script by passing arguments fun 1 2 3 I want to check the no. of arguments passed to fun1 function in the same functionbefore validation. can any one suggest me. (2 Replies)
Discussion started by: KiranKumarKarre
2 Replies

4. Shell Programming and Scripting

How to make shell script arguments optional?

Here is my script: #!/bin/ksh usage () { echo " Usage: $0 <opt1> <opt2> <opt3> <opt4>" } if ; then usage exit; fi prog -a $1 -b $2 -c $3 -d $4 2>&1 | tee -a ~/$1.log I want argument 4 to be optional, so if there's no argument for opt4, that it doesn't... (8 Replies)
Discussion started by: guitarscn
8 Replies

5. Shell Programming and Scripting

Using arguments in Shell script

Hello, I have to make a shell script doing that : the program tests if there is an argument, if there is it checks whether this is a directory or not, If it is it opens it. for any .c file in the directory it prints 2 lines in the screen : the dependence line of the .o and compiler commend... (1 Reply)
Discussion started by: dekl
1 Replies

6. Shell Programming and Scripting

sub arguments to shell script

Hi, I have a shell script, when run it i get a prompt to enter arguments say 1 for doing my next task otherwise q for quit. What I am trying to do is run the shell script with the argument passed in however it does not seem to work. This is what I did ./test.sh 1 Instead it printed the line... (6 Replies)
Discussion started by: aqua9
6 Replies

7. Shell Programming and Scripting

To run a local shell script in a remote machine by passing arguments to the local shell script

I need to run a local shell script on a remote machine. I am able to achieve that by executing the command > ssh -qtt user@host < test.sh However, when I try to pass arguments to test.sh it fails. Any pointers would be appreciated. (7 Replies)
Discussion started by: Sree10
7 Replies

8. Shell Programming and Scripting

How can multiple arguments be passed to shell script?

My requirement is that I want to pass similar argument to a shell script and process it in the script. Something like below: myScript.sh -c COMPONENT1 -c COMPONENT2 -a APPNote: -c option can be specified multiple times and -a is optional parameter I know this can be achieved using... (2 Replies)
Discussion started by: rajdeep_paul
2 Replies

9. Shell Programming and Scripting

Pass Arguments to Command from Shell Script

Hi all, I am working on a project, in which I have to connect to Bluetooth low energy device. I am able to connect and do data transfer from command line. But I want to do from script Here is my script #!/bin/bash #sudo hcitool -i hci0 lescan sleep 1 sudo hcitool -i hci0 lecc --random... (8 Replies)
Discussion started by: nithin@embdes
8 Replies

10. Shell Programming and Scripting

The shell script doesn't get arguments, but parse them

Hello, I have a simple shell script, which starts from crontab like this: 00 03 * * 2-6 /export/applications/dte/sh/fwmarg.sh > /export/applications/dte/data/cron_log/fwmarg.cronlog.`date +\%m.\%d` 2>&1 The script doesn't get any argument. But inside it I see the line ... (10 Replies)
Discussion started by: digioleg54
10 Replies
localeadm(1M)															     localeadm(1M)

NAME
localeadm - query and configure locales SYNOPSIS
localeadm [-lcst] [-q locale | region] [-h] [-d device...] [-V] localeadm -r locale | region [-t] [-v] [-m] [-R root_path] localeadm -a locale | region [-t] [-v] [-m] [-d device...] [-R root_path] localeadm -f locale | region [-t] [-v] [-m] [-d device...] [-R root_path] localeadm -h The localeadm utility queries and configures Solaris locales through a command line interface. In query (-q) or list (-l) modes, localeadm displays information about locale packages that are installed on the system or that reside on a particular device or directory. To make it easier for users to pick out locales, the output from localeadm consists of a list of country or region names rather than a list of packages. Users can use the output to determine which locales or regions to add or remove. When the user specifies a locale or region to add or remove using the name given by the output of the list mode, localeadm calculates which locale packages need to be changed and add or remove them. localeadm uses pkgadd(1M) or pkgrm(1M) to add or remove packages. If the locales changed were Asian locales, then extra processes such as input method server daemons might need to be started before the new locales work properly. Once the locales are installed, the user is prompted to either reboot the machine or manually start the daemons. The user is also given a list of daemons which need to be started. All locales are part of a set geographic region. A locale is an indivisible part of a region. You cannot have a locale which doesn't exist in a region, or a region without locales. If you choose to add or remove a particular locale, all of the locales in the region to which it belongs will be added or removed. Likewise, if you query a locale, localeadm checks the system for the region of which the local is part. The following options are supported: -a locale | region Add the packages for locale (locale) or geographic region region to the system. Specify locale or region as the short name displayed by the -l option. For example, the -l option outputs Australa- sia (aua), therefore, the argument for -a is aua. This option requires the -d option with arguments. If necessary packages are already installed, localeadm does not overwrite them. It simply skips such packages. If you use the -a and -m options with a locale that has already been added without message pkgs, it adds the mes- sage pkgs for that locale to the system. Only superusers or others who have been assigned package administration access through role-based access control can use this option. See rbac(5) for information on adding and removing packages. See smc(1M) for information on setting up and adding users to a package manager role. -c Display the locale name with codeset in locale(1) format. Use this option in conjunction with the -l option to display the locale name with codeset in the format shown by the locale(1) command. For example, it displays fr_FR.ISO8859-1 as opposed to french. -d device Install or list locales from packages located in device. Specify device as a full path name to a directory contain- ing Solaris packages or the path to the top directory of a complete Solaris image. You can also specify device as a device alias such as /cdrom/cdrom0, a device nickname as defined by eject(1), or an alternative device nickname such as cdrom, dvd or dvdrom. If the packages are to be installed from a series of CDROM images, then multiple images can be specified in a comma separated list. The same device or nickname can be repeated to indicate multiple loadings of different media at the same device. -f Check the pkgs modified by a previous add or remove operation to ensure all pkgs were added or removed properly. If a pkg was incorrectly added due to a pkgadd or pkgrm failure, the pkg is backed out and reinstalled. Only superusers or others who have been assigned package administration access through role-based access control can use this option. See rbac(5) for information on adding and removing packages. See smc(1M) for information on setting up and adding users to a package manager role. -h Print a short help message. The help message lists all the flags and their usage. -l List all the locales that are installed on the system or available on an install media. The list is sorted by geo- graphic region. When you specify the -d option with -l, localeadm lists all of the locales or regions available on the device pointed to by the -d option arguments. When you do not specify the -d option, localeadm -l lists all of the locales or regions installed on the current system. When you specify the -t option with -l, localeadm lists all of the locales or regions that could possibly be added to the system. -m Deselect translated message packages. By default, with the -a option, localeadm adds the translated message packages for the locale or region specified in the -a option argument. If you use the -a option with -m, the translated message packages for the locale or region will not be added, thus effectively disabling the translated messages support for that locale/region. If used with -r option, localeadm will remove only the translated message packages for the locale or region specified in the -r option argument. If you use the -m option with a locale that has already been added without message pkgs, it adds the message pkgs for that locale to the system. -q locale | region Query the system to see if the locale (locale) or geographic region region are already installed. The expected input for a locale or region name is the name displayed by the -l option. -r locale | region Remove the packages for locale (locale) or geographic region (region) from the system. Specify locale or region as the short name displayed by the -l option. For example, the -l option outputs Australa- sia (aua), therefore, the argument for -a is aua. Only superusers or others who have been assigned package administration access through role-based access control can use this option. See rbac(5) for information on adding and removing packages. See smc(1M) for information on setting up and adding users to a package manager role. -R root_path Define the full path name of a directory to use as the root path. All files, including package system information files, are relocated to a directory tree starting in the specified root_path. You can specify root_path when you install to a client from a server. Note - The root file system of any non-global zones must not be referenced with the -R option. Doing so might dam- age the global zone's file system, might compromise the security of the global zone, and might damage the non-global zone's file system. See zones(5). -s Display only the geographic regions of specific locales or regions. Use this option in conjunction with the -l option to display listed regions or locales. -t Test mode. Use this option with -a, -f or -r to list all operations to be done. It will not actually add or remove packages. Use the this option with -l to list all of the locales or regions that could possibly be added to the system. -v Print out messages produced during a pkgadd or pkgrm command. This option works on localeadm add and remove commands. It does not work on individual pkgadd or pkgrm commands. It displays additional information, but only as part of the larger program. -V Display version information. Example 1: Listing All of the Locales and Codesets The following example lists all of the geographic regions installed on the machine. All locales in the regions are listed by their code- sets: example% localeadm -lc Example 2: Listing the Regions Available on a Solaris CD or DVD The following example command checks the Solaris_10/Product directory of the CD or DVD mounted on /cdrom/cdrom0. It also lists the names of the regions that can be installed from packages in that directory. The -s option displays the region names without any locales. example% localeadm -ls -d /cdrom/cdrom0 Example 3: Querying for a Locale The following example queries whether the Central European region called ceu on the current machine. example% localeadm -q ceu Example 4: Removing Western European Locales The following example removes all packages associated with the Western Europe region from the system, except for those packages needed by other regions. example% localeadm -r weu Example 5: Adding Russian Locales The following example installs the Eastern Europe region, of which Russian locale is a part, from packages located in /net/sparc_images/export/pkgs. example# localeadm -a ru_RU -d /net/sparc_images/export/pkgs Example 6: Adding the Traditional Chinese Locale The following example adds the Traditional Chinese region to the system. This differs from the previous example in that Traditional Chinese is installed as a geographic region rather than just a locale. This is the case for all Asian languages, for example, zh_TW, zh_CN, zh_HK, hi_IN, th_TH, ko_KR, ja. # localeadm -a zh_TW -d /net/sparc_images/export/pkgs The following exit values are returned when you invoke localeadmin without the -q (query) option: 0 Successful completion. 1 An error occurred. The following exit values are returned when you invoke localeadmin with the -q (query) option: 0 Successful search. The locale or region was found. 1 Unsuccessful search. The locale or region was not found. 2 An error occurred. /var/sadm/install/logs/localeadmin_install.date /var/sadm/install/logs/localeadmin_uninstall.date Log files for installation and removal operations. date is specified in YYYY_MM_DD format. If a particular day has multiple installs, date has a period (.) followed by a number appended to it, for example, 2003_10_20.1, 2003_10_20.2. /tmp/locales.list File that contains the output of the -l option. See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWladm | +-----------------------------+-----------------------------+ |Interface Stability |Evolving | +-----------------------------+-----------------------------+ eject(1), locale(1), pkgadd(1M), pkgrm(1M), smc(1M), attributes(5), rbac(5) 6 Apr 2005 localeadm(1M)
All times are GMT -4. The time now is 02:52 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy