05-29-2008
How to build a command into a string rather than execute the command
I'm trying to populate a command line into a variable. It appears to be executing, instead. Here's an example:
mycmd=''
if ...; then
$mycmd='sudo '
fi
$mycmd=$mycmd 'sed -i prev s/aaa/bbb/' $myfile
res=`$mycmd`
(I'm also not sure of the best way to execute the command from the variable, either, so any corrections would be appreciated!)
Last edited by littlejon; 05-29-2008 at 08:56 PM..
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
Hi Group ,
I m trying to execute commands on some other system using write command but inspite of executing the commands they r passed as simple messages.
- i m writing
>write user-id
! ls
o
ctrl-d
inspite of executing the command ls,other terminal shows ! ls.
Thnx in advance. (2 Replies)
Discussion started by: Aashish
2 Replies
2. Shell Programming and Scripting
my description from another thread...
here's my code:
#!/bin/bash
IFS=$'\n'
function OutputName() {
input=$1
echo $input
input=`echo "$input" | sed -e 's/.//'`
input=`echo "$input".avi`
output_name=$input
}
if ]; then
echo... (5 Replies)
Discussion started by: TinCanFury
5 Replies
3. Shell Programming and Scripting
I am using an array to store some data (keys e.g 47975081_1215781266128), it can be assumed that it is key to other data.
I want extract data from a file based on a couple of keys (range) and store the resulting data in a variable using the following command:
sed -n... (9 Replies)
Discussion started by: gugs
9 Replies
4. Shell Programming and Scripting
Hello everyone.
I am using the select command to build a menu, here is my question:
Is it possible to generate a menu which contains several sections and have a separator between the sections without having a selection number generated in front of the separator?
This is a sample of what I would... (1 Reply)
Discussion started by: gio001
1 Replies
5. Shell Programming and Scripting
Hi All
I am trying to build a script that will take data from a tab separated file and use that to split up a quicktime file. So far the code is as follows
#!/bin/sh
#test parsing of data
#fix excel file output returns
cat $1 | tr "\r" "\n" > $1.fix
printf "\n" >> $1.fix
mv $1.fix $1
... (3 Replies)
Discussion started by: babajuma
3 Replies
6. Shell Programming and Scripting
Hi,
Here's the problem I am facing.
This is just an example:
list_files.ksh
------------
dir=$1
match=$2
var="ls $dir | grep $match"
files=`"$var"`
I get the below error on executing the above script:
./list_files.ksh: ls /home/my_files | grep xml: not found
I know I... (2 Replies)
Discussion started by: dips_ag
2 Replies
7. Shell Programming and Scripting
I am running the export command within a view to use that value inside my build script. But while executing it it is saying "export command not found"
My code is as follows:
--------------------------
#!/bin/sh
user="test"
DIR="/bldtmp/"$user
VIEW="test.view1"
echo "TMPDIR before export... (4 Replies)
Discussion started by: dchoudhury
4 Replies
8. Shell Programming and Scripting
Hi Experts,
I am very much new to linux scripting, I am currently working on reducing my manual work and hence writing a script to automate few task.
I am running below command to snmpwalk the router..
snmpwalk -v 3 -u WANDL_SU -a MD5 -A vfipmpls -x DES -X VfIpMpLs -l authPriv... (19 Replies)
Discussion started by: Hanumant.madane
19 Replies
9. Shell Programming and Scripting
Hello :)
new to bash not to programming.
I have an on-going need to change the owning group on sets of files and directories from the one they were created with or changed to on update to the one they need to have going forward.
find {target_root} -group wrong_group
gets me a newline... (4 Replies)
Discussion started by: naftali
4 Replies
10. Shell Programming and Scripting
Hello i am having an issue with bash script and this is the code
now=$(cat hosts1.txt | awk '{print $2;}')
while read n ;do
ssh root@$now 'useradd test1; echo -e "test1\ntest1" | passwd test1 && echo "test1 ALL=(ALL:ALL) ALL" >> /etc/sudoers'
When i execute only part with cat, it... (8 Replies)
Discussion started by: tomislav91
8 Replies
LEARN ABOUT OPENSOLARIS
builtin
builtin(1) User Commands builtin(1)
NAME
builtin - ksh93 built-in function to add, delete, or display shell built-ins
SYNOPSIS
builtin [-ds] [-f lib] [pathname ...]
DESCRIPTION
The ksh93 builtin command adds, deletes, or displays built-in commands in the current shell environment. A built-in command executes in the
current shell process and can have side effects in the current shell. On most systems, the invocation time for built-in commands is one or
two orders of magnitude less than commands that create a separate process.
For each pathname specified, the basename of the pathname determines the name of the built-in. For each basename, the shell looks for a C
level function in the current shell whose name is determined by pre-pending b_ to the built-in name. If pathname contains a forward slash
(/), the built-in is bound to pathname. A built-in bound to a pathname is only executed if pathname is the first executable found during a
path search. Otherwise, built-ins are found prior to performing the path search.
If pathname is not specified, builtin displays the current list of built-ins, or just the special built-ins if the -s option is specified,
on standard output. The full pathname for built-ins that are bound to pathnames are displayed.
Libraries containing built-ins can be specified with the -f option. If the library contains a function named lib_init(), this function is
invoked with argument 0 when the library is loaded. The lib_init() function can load built-ins by invoking an appropriate C level function.
In this case there is no restriction on the C level function name.
The C level function is invoked with three arguments. The first two are the same as main() and the third one is a pointer.
The ksh93 builtin command cannot be invoked from a restricted shell.
OPTIONS
The following options are supported:
-d Delete each of the specified built-ins. Special built-ins cannot be deleted.
-f lib On systems with dynamic linking, load and search for built-ins in the shared library, lib.
Libraries are searched for in $PATH and system dependent library directories. The system dependent shared library prefix or suf-
fix can be omitted. Once a library is loaded, its symbols become available for the current and subsequent invocations of builtin.
Multiple libraries can be specified with separate invocations of builtin. Libraries are searched in the reverse order in which
they are specified.
-s Display only the special built-ins.
OPERANDS
The following operands are supported:
pathname Specifies the pathname. The basename of the pathname determines the name of the built-in.
EXIT STATUS
The following exit values are returned:
0 Successful completion.
>0 An error occurred.
EXAMPLES
Example 1 Loading a builtin Command
The following example loads a builtin command mycmd from the library libfoo.so:
example% builtin -f foo mycmd
AUTHORS
David Korn, dgk@research.att.com
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|Availability |SUNWcsu |
+-----------------------------+-----------------------------+
|Interface Stability |Uncommitted |
+-----------------------------+-----------------------------+
SEE ALSO
ksh93(1), whence(1), attributes(5)
SunOS 5.11 1 May 2007 builtin(1)