LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-10-2013, 04:08 AM   #1
nuser
LQ Newbie
 
Registered: Jun 2012
Distribution: open suse 12.2
Posts: 17

Rep: Reputation: Disabled
Bash ,to work under MAC OS


Hello, can anyone help by showing how the script should look to work under Mac OS!
Code:
#!/bin/bash

USR=$(logname)
f=`find /home/$USR/proba -name "*.doc" -o -name "*.xsl" -o -name "*.pdf"`

for file in $f
do
   chattr +i $f
done
I want to achieve the same result!
 
Old 02-10-2013, 10:48 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by nuser View Post
Hello, can anyone help by showing how the script should look to work under Mac OS!
Code:
#!/bin/bash
USR=$(logname)
f=`find /home/$USR/proba -name "*.doc" -o -name "*.xsl" -o -name "*.pdf"`

for file in $f
do
   chattr +i $f
done
I want to achieve the same result!
Ok...so what happens when you run this on a Mac?? And you do realize that Mac OS is NOT Linux, right? So unless you have all the same utilities (that also take the same command-line attributes), the script won't work. Same with path names, etc.

If you want to know about Mac shell scripting, Apple has a scripting tutorial...have you read it?
http://developer.apple.com/library/m...roduction.html
 
Old 02-10-2013, 11:04 AM   #3
nuser
LQ Newbie
 
Registered: Jun 2012
Distribution: open suse 12.2
Posts: 17

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TB0ne View Post
Ok...so what happens when you run this on a Mac?? And you do realize that Mac OS is NOT Linux, right? So unless you have all the same utilities (that also take the same command-line attributes), the script won't work. Same with path names, etc.

If you want to know about Mac shell scripting, Apple has a scripting tutorial...have you read it?
http://developer.apple.com/library/m...roduction.html
I wrote this script myself, and I know the differences but I have not Mac on hand to experiment. I was hoping someone who has experience with Mac to help me because there is no way to check the result. To put it short I have no choice but to write someone for me. If you have no experience with this, do not write in vain. I wrote this script for 2 minutes if you know how and you have two minutes write/type the right commands!Please!
 
Old 02-10-2013, 01:59 PM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by nuser View Post
I wrote this script myself, and I know the differences but I have not Mac on hand to experiment. I was hoping someone who has experience with Mac to help me because there is no way to check the result. To put it short I have no choice but to write someone for me. If you have no experience with this, do not write in vain. I wrote this script for 2 minutes if you know how and you have two minutes write/type the right commands!Please!
There is no way anyone here can know what knowledge you have...we know what you post. You asked for assistance, and you were given a link and advice that could help you. Now you say that you know the differences (implying that you are experienced in Mac scripting).

If you want someone to do work for you, then you need to pay them. Otherwise, you need to do the work yourself...this is true for ANYTHING, from writing a script, to painting a house. Otherwise, you can find a friend with a Mac, or buy one, and do it yourself. There are even options for you to get Mac OS running in a virtual machine, which you can find on the Internet. Those are three options for you to do it yourself; if you want someone to do it for you, post the job in the LQ Job Marketplace.

And if you're going to reply rudely when people offer you help, you probably won't get people offering to help you, much less do work for you.

Last edited by TB0ne; 02-10-2013 at 02:01 PM.
 
Old 02-10-2013, 02:03 PM   #5
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939
"Mac OS" (as in System-9) is not Unix-based. OS/X, however, is.

OS/X is based on the Mach (BSD Unix) kernel, not Linux, and although many of the commands are similar, they are not entirely.
 
Old 02-11-2013, 12:17 AM   #6
nuser
LQ Newbie
 
Registered: Jun 2012
Distribution: open suse 12.2
Posts: 17

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TB0ne View Post
There is no way anyone here can know what knowledge you have...we know what you post. You asked for assistance, and you were given a link and advice that could help you. Now you say that you know the differences (implying that you are experienced in Mac scripting).

If you want someone to do work for you, then you need to pay them. Otherwise, you need to do the work yourself...this is true for ANYTHING, from writing a script, to painting a house. Otherwise, you can find a friend with a Mac, or buy one, and do it yourself. There are even options for you to get Mac OS running in a virtual machine, which you can find on the Internet. Those are three options for you to do it yourself; if you want someone to do it for you, post the job in the LQ Job Marketplace.

And if you're going to reply rudely when people offer you help, you probably won't get people offering to help you, much less do work for you.
Excuse me if I sound rude!
 
Old 02-11-2013, 12:10 PM   #7
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Code:
#!/bin/bash

USR=$(logname)
f=`find /home/$USR/proba -name "*.doc" -o -name "*.xsl" -o -name "*.pdf"`

for file in $f
do
   chattr +i $f
done
Well, your first problem is you're using "chattr +i $f" instead of "chattr +i $file".

But more importantly, you've fallen for the incredibly common Don't Read Lines With For error. This is compounded by your attempt to store the output of find inside a single, scalar variable.

Finally, you need to learn how to properly quote variables, a vital concept in scripting.
http://mywiki.wooledge.org/Arguments
http://mywiki.wooledge.org/WordSplitting
http://mywiki.wooledge.org/Quotes


Instead of for, use a while+read loop, preferably with -print0 null separators (be sure your version of find supports it).

Code:
while IFS='' read -rd '' fname; do

    chattr +i $fname"

done < <( find "/home/$USR/proba" \( -name "*.doc" -o -name "*.xsl" -o -name "*.pdf" \) -print0 )
How can I read a file (data stream, variable) line-by-line (and/or field-by-field)?
http://mywiki.wooledge.org/BashFAQ/001

And here are a couple of good links about using find:
http://mywiki.wooledge.org/UsingFind
http://www.grymoire.com/Unix/Find.html


PS: $(..) is highly recommended over `..`
 
Old 02-11-2013, 01:37 PM   #8
nuser
LQ Newbie
 
Registered: Jun 2012
Distribution: open suse 12.2
Posts: 17

Original Poster
Rep: Reputation: Disabled
@David the H. Thanks for the good advices!
 
  


Reply



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
Why does this work from the bash command line and then fails in a bash script? Rupadhya Linux - Newbie 5 09-26-2012 12:05 AM
LXer: 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X LXer Syndicated Linux News 0 06-11-2012 10:00 AM
How to: run bash file in Linux which is initiated from a Windows/Mac system adeoux Linux - General 4 04-28-2012 05:40 PM
mac osx and bash sulekha Other *NIX 4 09-27-2008 11:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:51 PM.

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
Open Source Consulting | Domain Registration