LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-17-2010, 02:24 AM   #1
JoelSmit
LQ Newbie
 
Registered: Jul 2010
Location: Netherlands
Distribution: CentOS
Posts: 5

Rep: Reputation: 0
First steps script


Hi guys,

I'm getting an error in line 3:

Quote:
#!/bin/sh
echo Enter File Name
set file=$<
if ( -w $file) then
cat $file
else
chmod ugo+w $file
fi
what am I doing wrong?
I've tried all kinds of combination in that line, none work.

Thanks,
Joel
 
Old 07-17-2010, 02:40 AM   #2
sag47
Senior Member
 
Registered: Sep 2009
Location: Orange County, CA
Distribution: Kubuntu x64, Raspbian, CentOS
Posts: 1,831
Blog Entries: 36

Rep: Reputation: 451Reputation: 451Reputation: 451Reputation: 451Reputation: 451
Code:
if [ -w $file]; then
fixed

google conditional shell script
http://www.dreamsyssoft.com/sp_ifelse.jsp

edit:I misinterpreted what you wanted. I thought you meant command 3...
Anyway google user input shell script. You want the read command.
http://unixhelp.ed.ac.uk/scrpt/scrpt2.3.html

Last edited by sag47; 07-17-2010 at 02:51 AM.
 
Old 07-17-2010, 03:01 AM   #3
JoelSmit
LQ Newbie
 
Registered: Jul 2010
Location: Netherlands
Distribution: CentOS
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks sag,

it tells that there is something wrong in line 3
Quote:
set file=$<
but I can't figure out what...

thanks,
Joel
 
Old 07-17-2010, 03:22 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Actually you mixed syntax of C-shell and Bourne shell. $< is valid only in C-shells and it's replaced by the next line of standard input. Here are two versions of the same script, one in tcsh, the other in bash. Please, check the differences:
Code:
#!/bin/tcsh
echo "Enter File Name: "
set file=$<
if ( -w $file ) then
  cat $file
else
  chmod ugo+w $file
endif
Code:
#!/bin/bash
read -p "Enter File Name: " file
if [ -w $file ] ; then
  cat $file
else
  chmod ugo+w $file
fi
Hope this helps.
 
Old 07-17-2010, 03:30 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,245

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
Hi Joel

What are you expecting that line to do?

Edit: Beaten by the master again ... lol
 
Old 07-17-2010, 04:17 AM   #6
JoelSmit
LQ Newbie
 
Registered: Jul 2010
Location: Netherlands
Distribution: CentOS
Posts: 5

Original Poster
Rep: Reputation: 0
Thumbs up

It works!

Thank you all!

I just had the wrong shell (like you said)

It doesn't work with /bin/sh but does with /bin/csh
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Shuttleworth steps down as Ubuntu 10.04 alpha steps up LXer Syndicated Linux News 0 12-18-2009 10:50 AM
A script that renames a folder to an integer after some other steps... Cyberman Programming 5 09-11-2007 08:32 AM
what are the steps for 2.6.8.1 mrlucio79 Red Hat 2 09-01-2004 09:46 AM
Steps To Security MeMo Linux - Security 1 06-10-2004 04:53 AM


All times are GMT -5. The time now is 02:27 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration