Sponsored Content
Top Forums Shell Programming and Scripting Handling filenames with spaces Post 303023830 by Ralph on Sunday 23rd of September 2018 01:34:05 PM
Old 09-23-2018
Quote:
Originally Posted by Scrutinizer
--
An alternative while using strings:

Code:
filesToShow=`ls -Q`
oldIFS=$IFS
IFS=$'\n'
for file in $filesToShow ; do
   echo "$file"
done
IFS=$oldIFS

Both versions worked fine. Why do you write IFS=$'\n' ? It worked for me without the $. But shouldn't now a newline be used to split the fields? (There's no newline in the variable.)

Last edited by Ralph; 09-23-2018 at 03:05 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

handling spaces in unix

I am testing a ksh script for email. In the script I receive several parameters. One of them is a subject. The subject may contain spaces. Ex. Test this. When I am running the script on telnet to test, how should the syntax at the command line be written. I have this: ksh ResendE.sh '001111'... (2 Replies)
Discussion started by: supercbw
2 Replies

2. Shell Programming and Scripting

spaces in filenames

I have a problem with the script below #!/bin/sh for vo in `find -maxdepth 1 -type f -regex "^\./*$"` do ls -l "$vo" some other commands done It works fine until `find ...` returns files with spaces. I've tryed to change IFS but haven't succeed Any solutions? (4 Replies)
Discussion started by: Hitori
4 Replies

3. Shell Programming and Scripting

how to handle spaces in filenames

I'm trying to do something like that: for $filename in `ls -1` do some_command $filename done but it doesn't work properly for file names with spaces, for...in splits at spaces. Anyway around? (4 Replies)
Discussion started by: rayne
4 Replies

4. Shell Programming and Scripting

Unix filenames and spaces

I have files on my unix boxes that users have created with spaces. Example: /tmp/project plan ls -l "/tmp/project plan" works fine. $/tmp>ls -l "/tmp/project plan" -rw-r--r-- 1 root other 0 Jan 31 12:32 /tmp/project plan I created a file called test and put just the... (2 Replies)
Discussion started by: x96riley3
2 Replies

5. Shell Programming and Scripting

spaces in filenames, for do

Hi All, I see similar problems in past threads but so far no answers have worked for me. I am trying to write a script which parses a txt file that contains one filename per line, then finds those files on the local disk and copies them to a specified directory. What I have: ... (4 Replies)
Discussion started by: naviztirf
4 Replies

6. Shell Programming and Scripting

spaces in filenames

Hi I hope someone will be able to resolve this little teaser! I am running a script for file in `ls directory` do echo "$file" ...other code here.... done this works fine unless we receive a file with a name which has a space in it ie "filena me" (I know its not good... (8 Replies)
Discussion started by: Bab00shka
8 Replies

7. Shell Programming and Scripting

Moving filenames containing spaces

I want to ftp all the sh files in the directory. Also if any of the file name contains spaces in them, it should be converted to underscores before it is ftped. I wrote the following code below: FILESSH=$(ls /mysh/*.sh) --- FILESH being used here for some other task --- echo "$FILESSH" |... (3 Replies)
Discussion started by: amicon007
3 Replies

8. Shell Programming and Scripting

Handling blank spaces

Hi, I am trying to replace a specific column values in a csv file with double quotes when I am find embedded spaces with in the fields. Example: SNO,NAME,ZIPCODE,RANK,SEX,ADDRESS 1,Robert,74538,12,34, M,Robert Street, NY 2,Sam,07564,13,M,12 Main Ave, CA 3,Kim, Ed,12345,14,M,123D ,... (1 Reply)
Discussion started by: techmoris
1 Replies

9. Shell Programming and Scripting

awk and spaces in filenames

Hey there, this is my first post and I'll try to explain my situation as best I can.Here is a sample of the input file: ADO Sample.h,v ADO Sample 2010-05-21 lyonsb /repository/patents/TSCommon/OpenSource/Dundass/ug6mfc/DataSources/Ado/ADO Sample ADO SampleDoc.h,v ADO SampleDoc 2010-05-21... (3 Replies)
Discussion started by: rodan90
3 Replies

10. Shell Programming and Scripting

removing spaces in filenames

I have a problem mounting images because of the spaces in the filenames. Does anyone know how to rename files by removing the spaces with the find command? find Desktop/$dir -name "*.dmg" -print -exec ??? (4 Replies)
Discussion started by: ianebaj
4 Replies
command(1)							   User Commands							command(1)

NAME
command - execute a simple command SYNOPSIS
command [-p] command_name [argument...] command [-v | -V] command_name DESCRIPTION
The command utility causes the shell to treat the arguments as a simple command, suppressing the shell function lookup. If the command_name is the same as the name of one of the special built-in utilities, the special properties will not occur. In every other respect, if command_name is not the name of a function, the effect of command (with no options) will be the same as omitting command. The command utility also provides information concerning how a command name will be interpreted by the shell. See -v and -V. OPTIONS
The following options are supported: -p Performs the command search using a default value for PATH that is guaranteed to find all of the standard utilities. -v Writes a string to standard output that indicates the path or command that will be used by the shell, in the current shell execu- tion environment to invoke command_name, but does not invoke command_name. o Utilities, regular built-in utilities, command_names including a slash character, and any implementation-provided functions that are found using the PATH variable will be written as absolute path names. o Shell functions, special built-in utilities, regular built-in utilities not associated with a PATH search, and shell reserved words will be written as just their names. o An alias will be written as a command line that represents its alias definition. o Otherwise, no output will be written and the exit status will reflect that the name was not found. -V Writes a string to standard output that indicates how the name given in the command_name operand will be interpreted by the shell, in the current shell execution environment, but does not invoke command_name. Although the format of this string is unspecified, it will indicate in which of the following categories command_name falls and include the information stated: o Utilities, regular built-in utilities, and any implementation-provided functions that are found using the PATH variable will be identified as such and include the absolute path name in the string. o Other shell functions will be identified as functions. o Aliases will be identified as aliases and their definitions will be included in the string. o Special built-in utilities will be identified as special built-in utilities. o Regular built-in utilities not associated with a PATH search will be identified as regular built-in utilities. o Shell reserved words will be identified as reserved words. OPERANDS
The following operands are supported: argument One of the strings treated as an argument to command_name. command_name The name of a utility or a special built-in utility. EXAMPLES
Example 1: Making a version of cd that always prints out the new working directory exactly once cd() { command cd "$@" >/dev/null pwd } Example 2: Starting off a ``secure shell script'' in which the script avoids being spoofed by its parent IFS=' ' # The preceding value should be <space><tab><newline>. # Set IFS to its default value. unalias -a # Unset all possible aliases. # Note that unalias is escaped to prevent an alias # being used for unalias. unset -f command # Ensure command is not a user function. PATH="$(command -p getconf _CS_PATH):$PATH" # Put on a reliable PATH prefix. # ... At this point, given correct permissions on the directories called by PATH, the script has the ability to ensure that any utility it calls is the intended one. It is being very cautious because it assumes that implementation extensions may be present that would allow user func- tions to exist when it is invoked. This capability is not specified by this document, but it is not prohibited as an extension. For exam- ple, the ENV variable precedes the invocation of the script with a user startup script. Such a script could define functions to spoof the application. ENVIRONMENT VARIABLES
See environ(5) for descriptions of the following environment variables that affect the execution of command: LANG, LC_ALL, LC_CTYPE, LC_MESSAGES, and NLSPATH. PATH Determine the search path used during the command search, except as described under the -p option. EXIT STATUS
When the -v or -V options are specified, the following exit values are returned: 0 Successful completion. >0 The command_name could not be found or an error occurred. Otherwise, the following exit values are returned: 126 The utility specified by command_name was found but could not be invoked. 127 An error occurred in the command utility or the utility specified by command_name could not be found. Otherwise, the exit status of command will be that of the simple command specified by the arguments to command. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ SEE ALSO
sh(1), type(1), attributes(5), environ(5), standards(5) SunOS 5.10 17 Jul 2002 command(1)
All times are GMT -4. The time now is 03:45 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy