HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Need Help for C shell variables assigment from fil...
Operating System - HP-UX
1827819
Members
1888
Online
109969
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2003 03:35 AM
12-19-2003 03:35 AM
Need Help for C shell variables assigment from file
Hi Everyone,
I was hoping that someone might know of a way to handle this using C shell.
Basically I'm trying to write a csh script that will look into a directory on a hpux machine that is a samba share. I want to do a number of things to the files in this directory in a batch mode from this script.
I first "ls" and redirect the listing to a file, I then read the file 1 line at a time and assign the files' filename to a var for use in later opperations.
Here is my problem, this directory hold many files from windows based systems and many have spaces in their names (which the scipt can deal with) however some files have multipule spaces in a row within the filename and when the name is assigned to the var, it loses any multipule space no matter how I try to quote it or what utility I use to read the filelist I.E. sed,awk etc..
Here is a little script that will illistrate the problem.
1) it will create a "test" dir under /tmp
2) it will touch 2 files with multipule spaces in there names.
3)it will then put the names into a list which
contains the right filenames with the spaces.
4) then it will try to assign 1 filename at a time from the list to a var.
You will then see that the var has the filename but with only 1 space where there were multipules.
Here is the scripts text
-------------------------
#!/bin/csh -f
cd /tmp
mkdir test
cd test
touch "test file with three spaces"
touch "test file with four spaces"
set f_cnt = 1
set f_max = 0
ls -1A > /tmp/filelist
@ f_max = `cat /tmp/filelist | wc -l`
while (${f_cnt} <= ${f_max})
set src_file = `sed -n "${f_cnt}p" /tmp/filelist`
if (${#src_file} == 0) exit
set new_file = "${src_file}.new"
echo "names read to vars from file"
echo "${src_file}"
echo "${new_file}"
echo "mv command fails"
mv "${src_file}" "{new_file}"
@ f_cnt++
end
echo "names in filelist"
cat /tmp/filelist
------------------------
HELP !!!
If someone could please show me how to read one line at a time from a file and assign it to a var in c shell and have the var maintain the multipule spaces so that the var can then be used to "mv" "del" or whatever on the file from a script.
Thanks
Rick
I was hoping that someone might know of a way to handle this using C shell.
Basically I'm trying to write a csh script that will look into a directory on a hpux machine that is a samba share. I want to do a number of things to the files in this directory in a batch mode from this script.
I first "ls" and redirect the listing to a file, I then read the file 1 line at a time and assign the files' filename to a var for use in later opperations.
Here is my problem, this directory hold many files from windows based systems and many have spaces in their names (which the scipt can deal with) however some files have multipule spaces in a row within the filename and when the name is assigned to the var, it loses any multipule space no matter how I try to quote it or what utility I use to read the filelist I.E. sed,awk etc..
Here is a little script that will illistrate the problem.
1) it will create a "test" dir under /tmp
2) it will touch 2 files with multipule spaces in there names.
3)it will then put the names into a list which
contains the right filenames with the spaces.
4) then it will try to assign 1 filename at a time from the list to a var.
You will then see that the var has the filename but with only 1 space where there were multipules.
Here is the scripts text
-------------------------
#!/bin/csh -f
cd /tmp
mkdir test
cd test
touch "test file with three spaces"
touch "test file with four spaces"
set f_cnt = 1
set f_max = 0
ls -1A > /tmp/filelist
@ f_max = `cat /tmp/filelist | wc -l`
while (${f_cnt} <= ${f_max})
set src_file = `sed -n "${f_cnt}p" /tmp/filelist`
if (${#src_file} == 0) exit
set new_file = "${src_file}.new"
echo "names read to vars from file"
echo "${src_file}"
echo "${new_file}"
echo "mv command fails"
mv "${src_file}" "{new_file}"
@ f_cnt++
end
echo "names in filelist"
cat /tmp/filelist
------------------------
HELP !!!
If someone could please show me how to read one line at a time from a file and assign it to a var in c shell and have the var maintain the multipule spaces so that the var can then be used to "mv" "del" or whatever on the file from a script.
Thanks
Rick
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2003 06:01 AM
12-19-2003 06:01 AM
Re: Need Help for C shell variables assigment from file
There is missing $ in mv line.
It should be
mv "${src_file}" "${new_file}"
It should be
mv "${src_file}" "${new_file}"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2003 06:11 AM
12-19-2003 06:11 AM
Re: Need Help for C shell variables assigment from file
This question has already been solved. See:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=319408
Pete
Pete
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=319408
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2003 06:30 AM
12-19-2003 06:30 AM
Re: Need Help for C shell variables assigment from file
Thanks Everyone for your responses
Rod gave me the answer by using:
setenv src_file "`sed -n "${f_cnt}p" /tmp/filelist`"
instead of what I was using and now the
var keeps the multipule spaces between words.
Thank again Rod
Rod gave me the answer by using:
setenv src_file "`sed -n "${f_cnt}p" /tmp/filelist`"
instead of what I was using and now the
var keeps the multipule spaces between words.
Thank again Rod
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Support
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP