Sponsored Content
Special Forums Windows & DOS: Issues & Discussions Setting a variable to result of FIND command Post 65873 by Perderabo on Wednesday 9th of March 2005 09:17:39 PM
Old 03-09-2005
I decided to tackle part of this problem. My quest: write a bat file to set the environment variable x to the output of the "cd" command. I am using the newer cmd.exe on Windows XP rather than the older command.exe. Even so, this was harder than it sounds. My final bat file:
Code:
set x=hello
echo before loop %x%

for /f "usebackq" %%x in (`cd`) do (
      echo in loop x = %%x
      set x=%%x
)

echo after loop %x%

That '/f "usebackq"' option on the "for" statement is the only thing I found that can parse the output of a program. And the variable in the "for" statement seems to not be an environment variable, so I had to do that explicit "set" in the loop.
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

find command not returning any result

I am looking for all the header files (*.h).. which as per documentation of the UNIX system shouldbe there. I am using find / -name *.h -print But it does't give anything. My question is under what condition the "find" condition will fail to find the file? What is the work around. ... (4 Replies)
Discussion started by: rraajjiibb
4 Replies

2. Shell Programming and Scripting

storing result of a command in variable

For whatever reason I cant seem to fix my syntax to do the following. I want to run a grep and count how many instances come up and store that number in a variable but I keep erroring out. Here's my code in bash: number=grep blah file.txt | wc -l (1 Reply)
Discussion started by: eltinator
1 Replies

3. Shell Programming and Scripting

sh : Problem with the result of a find command

Hi I'm working on solaris and I'm trying to run a script. The part listed here does not work properly, the result of the find command is not in the output file /tmp/result (I've checked the find command , executing the shell with sh -x , it seems correct). It seems like I've lost the standard... (4 Replies)
Discussion started by: frenchwill
4 Replies

4. Shell Programming and Scripting

assign awk command result to a variable

#!/bin/sh # ## MYSTRING = `awk '/myApp.app/' /Users/$USER/Library/Preferences/loginwindow.plist` if then echo String not found defaults write /Users/$USER/Library/Preferences/loginwindow AutoLaunchedApplicationDictionary -dict-add -string Hide -bool YES -string Path -string... (9 Replies)
Discussion started by: dedmakar
9 Replies

5. UNIX for Dummies Questions & Answers

Find command - result order

Hi! Could you please explain why the result order isn't in reverse time order as it is requestet by "xargs ls -ltr" command (ksh shell)? There are about 5000 files in dir. $ find . -name "*201010*" -print |xargs ls -ltr |tail -rw-r--r-- 1 oracle oinstall 54326 Nov 25 20:32... (2 Replies)
Discussion started by: laki47
2 Replies

6. Windows & DOS: Issues & Discussions

Read command result as variable

Hi all, Is there a simple way to read a command output as a variable? I've running a batch file to do: attrib.exe * | find /c /v "" >filecount.txt but rather than write it to the txt file I'd like to read the total in as a variable to pass to the rest of the bat file... Any help much... (1 Reply)
Discussion started by: Grueben
1 Replies

7. Shell Programming and Scripting

Assign the result of a multiline command to a variable

Hi, I have the following command that lists all the .o files from all the directories except of vwin (which I don't want it) for i in `ls -d */*.o|awk '$0 !~ "vwin"'`; do echo $i; done The result is something like that dir1/file1.o dir1/file2.o dir2/file3.o etc. So, I want to create a... (9 Replies)
Discussion started by: scor6800
9 Replies

8. UNIX for Dummies Questions & Answers

Strange result using find command.

I created a file with the permissions of 776. When I ran the command find /root/Desktop -perm -644 -type f The created file shows up as part of the results. Doesn't -perm -mode mean that for global, only 4(read) and 2(write) can be accepted ? (2 Replies)
Discussion started by: Hijanoqu
2 Replies

9. Shell Programming and Scripting

Unexplained result of 'find' command

Given this bit of script: retprd=$1 find ${extrnllogdir} -name "*.log" -mtime +$retprd -exec ls -l {} \; >> $logfile produces this (with 'set -x') ++ find /xfers/oracle/dw/data -name '*.log' -mtime +60 -exec ls -l '{}' ';' find: /xfers/oracle/dw/data/cron: Permission denied Where is he... (5 Replies)
Discussion started by: edstevens
5 Replies

10. Shell Programming and Scripting

Linux find command seems to not transmit all the result to the '-exec command'

Hello. From a script, a command for a test is use : find /home/user_install -maxdepth 1 -type f -newer /tmp/000_skel_file_deb ! -newer /tmp/000_skel_file_end -name '.bashrc' -o -name '.profile' -o -name '.gtkrc-2.0' -o -name '.i18n' -o -name '.inputrc' Tha command... (3 Replies)
Discussion started by: jcdole
3 Replies
fileutil_traverse(n)						  file utilities					      fileutil_traverse(n)

__________________________________________________________________________________________________________________________________________________

NAME
fileutil_traverse - Iterative directory traversal SYNOPSIS
package require Tcl 8.3 package require fileutil::traverse ?0.4.1? package require fileutil package require control ::fileutil::traverse ?objectName? path ?option value...? $traverser command ?arg arg ...? $traverser files $traverser foreach filevar script $traverser next filevar _________________________________________________________________ DESCRIPTION
This package provides objects for the programmable traversal of directory hierarchies. The main command exported by the package is: ::fileutil::traverse ?objectName? path ?option value...? The command creates a new traversal object with an associated global Tcl command whose name is objectName. This command may be used to invoke various operations on the traverser. If the string %AUTO% is used as the objectName then a unique name will be generated by the package itself. Regarding the recognized options see section OPTIONS. Note that all these options can be set only during the creation of the traver- sal object. Changing them later is not possible and causes errors to be thrown if attempted. The object command has the following general form: $traverser command ?arg arg ...? Command and its arguments determine the exact behavior of the object. The following commands are possible for traversal objects: $traverser files This method is the most highlevel one provided by traversal objects. When invoked it returns a list containing the names of all files and directories matching the current configuration of the traverser. $traverser foreach filevar script The highlevel files method (see above) is based on this mid-level method. When invoked it finds all files and directories matching per the current configuration and executes the script for each path. The current path under consideration is stored in the variable named by filevar. Both variable and script live / are executed in the context of the caller of the method. In the method files the script simply saves the found paths into the list to return. $traverser next filevar This is the lowest possible interface to the traverser, the core all higher methods are built on. When invoked it returns a boolean value indicating whether it found a path matching the current configuration (True), or not (False). If a path was found it is stored into the variable named by filevar, in the context of the caller. The foreach method simply calls this method in a loop until it returned False. This method is exposed so that we are also able to incrementally traverse a directory hierarchy in an event-based manner. OPTIONS
-prefilter command_prefix This callback is executed for directories. Its result determines if the traverser recurses into the directory or not. The default is to always recurse into all directories. The callback is invoked with a single argument, the absolute path of the directory, and has to return a boolean value, True when the directory passes the filter, and False if not. -filter command_prefix This callback is executed for all paths. Its result determines if the current path is a valid result, and returned by next. The default is to accept all paths as valid. The callback is invoked with a single argument, the absolute path to check, and has to return a boolean value, True when the path passes the filter, and False if not. -errorcmd command_prefix This callback is executed for all paths the traverser has trouble with. Like being unable to change into them, get their status, etc. The default is to ignore any such problems. The callback is invoked with a two arguments, the absolute path for which the error occured, and the error message. Errors thrown by the filter callbacks are handled through this callback too. Errors thrown by the error callback itself are not caught and ignored, but allowed to pass to the caller, i.e. however invoked the next. Any other results from the callback are ignored. BUGS, IDEAS, FEEDBACK This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category fileutil of the Tcllib SF Trackers [http://sourceforge.net/tracker/?group_id=12883]. Please also report any ideas for enhancements you may have for either package and/or documentation. KEYWORDS
directory traversal, traversal CATEGORY
Programming tools fileutil 0.4.1 fileutil_traverse(n)
All times are GMT -4. The time now is 03:13 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy