Sponsored Content
Top Forums Shell Programming and Scripting Check if parameter passes in contains certain string Post 302225400 by consult4life on Friday 15th of August 2008 09:54:47 AM
Old 08-15-2008
While case...esac is fine, if you have your heart set on using 'expr' you can use expr this way:

expr $parameter : ".*$search" >/dev/null && echo Found!!!

In this form, expr returns the # of characters matched from the beginning of $parameter. That's why I had to put a ".*" in the beginning of the search string. Also, expr writes the number of characters matched to stdout (so I directed to /dev/null). Of course, you can just use this value in a test like this:

if [ expr $parameter : ".*$search" -gt 0 ]
then
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to check parameter variable?

Hello All, I have a script that will email out if the email address is specified as parameter 1. I am using ksh, and then tried the following : email=$1 Following did not work, I am getting error test -z $email test ${email:=" ") -eq " " test -n $email test ${?email} What... (4 Replies)
Discussion started by: negixx
4 Replies

2. Shell Programming and Scripting

Help with making a parameter check script.

I am making a script to check the parameters, but it seems that I can't catch the parameters by loop. $ cat sendmsg.sh #!/bin/sh ## Parameter Check i=0 max=$# while do PARAM=$${i} i=`expr ${i} + 1` echo ${PARAM} done How can I get the $1, $2, $3 by loop and set their... (2 Replies)
Discussion started by: GCTEII
2 Replies

3. Shell Programming and Scripting

Passing a string parameter to a function

I need to pass a parameter to a function in a script. My parameter is a string. When I display the parameter within my function, I only get the first word from string I pass in. How can I make the function receive the whole string (and not terminate at the first space it encounters)?. part of... (1 Reply)
Discussion started by: fastgoon
1 Replies

4. AIX

find {start} -ls - Two Passes?

I have a "find {start} -ls" command listing all files and dirs in on the whole filesystem. As part of this it lists locations that contain temporary files and, sometimes when executing, it identifies a file but produces an ERROR when trying to list it. ERROR thrown: find: bad status--... (2 Replies)
Discussion started by: apiggott
2 Replies

5. Shell Programming and Scripting

How to compare a parameter to a string

Hi, I have a parameter which is a string: set parameter = "string" I would like to compare it to various strings inside an IF conditional: if ($parameter == "string") then bla bla bla endif but it doesn't work, and I have no idea why. Thanks in advance, Shira. :) (12 Replies)
Discussion started by: shira
12 Replies

6. UNIX for Advanced & Expert Users

How to check what are the current kernel parameter settings

Hi all, I have four (4) different UNIX flavours and I want to know whether the following commands are correct with respect to wanting to check on what are my current kernel parameter settings. I just want to clear the doubts hanging over my head whether the commands below are the right ones... (2 Replies)
Discussion started by: newbie_01
2 Replies

7. Shell Programming and Scripting

Check input parameter

Hi all i need to check that if user has passed any input parameter while executing he shell script like ./test1.sh -a"-v" then do smothing if user execute the script without giving input paramater then ./test1.sh then do something how can we check this input parameter (6 Replies)
Discussion started by: aishsimplesweet
6 Replies

8. Shell Programming and Scripting

Check parameter is number or string

Hey I'm new in linux, I'm looking for a code to check whether the parameter is a number or a string. I have already tried this code: eerste=$(echo $1 | grep "^*$">aux) if But it doesn't work.:confused: Thanks (2 Replies)
Discussion started by: Eclecticaa
2 Replies

9. Shell Programming and Scripting

Duplicate check by passing external parameter

I have a code which is using to find duplicates in a files based on column.Below is the same code which is used to find duplicates in my file based on column 1 awk -F'|' '{if (x) { x_count++; print $0; if (x_count == 1) { print x } } x = $0}' FileName >Dup_File.txt But my requirement here is... (3 Replies)
Discussion started by: ginrkf
3 Replies
chroot(2)							System Calls Manual							 chroot(2)

NAME
chroot - Changes the effective root directory SYNOPSIS
#include <unistd.h> int chroot ( const char *path ); STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: chroot(): XPG4, XPG4-UNIX Refer to the standards(5) reference page for more information about industry standards and associated tags. PARAMETERS
Points to the new effective root directory. If the path parameter refers to a symbolic link, the chroot() function sets the effective root directory to the directory pointed to by the symbolic link. DESCRIPTION
The chroot() function causes the directory named by the path parameter to become the effective root directory. The effective root directory is the starting point when searching for a file's pathname that begins with a / (slash). The current working directory is not affected by the chroot() function. The calling process must have superuser privilege in order to change the effective root directory. The calling process must also have search access to the new effective root directory. The .. (dot-dot) entry in the effective root directory is interpreted to mean the effective root directory itself. Thus, .. (dot-dot) can- not be used to access files outside the subtree rooted at the effective root directory. RETURN VALUES
Upon successful completion, a value of 0 (zero) is returned. If the chroot() function fails, a value of -1 is returned and errno is set to indicate the error. ERRORS
If the chroot() function fails, the effective root directory remains unchanged and errno may be set to one of the following values: Search permission is denied for any component of the pathname. The path parameter points outside the process' allocated address space. An I/O error occurred while reading from or writing to the file system. More than MAXSYMLINKS symbolic links are encountered while resolving path. The length of the path argument exceeds PATH_MAX or a pathname component is longer than NAME_MAX. The path parameter does not exist or points to an empty string. A component of path is not a directory. The process does not have appropriate privilege. RELATED INFORMATION
Functions: chdir(2) Commands: cd(1) Standards: standards(5) delim off chroot(2)
All times are GMT -4. The time now is 05:13 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy