UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old April 4th, 2005, 01:11 AM
princesssonya princesssonya is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 5 princesssonya User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 53 m 24 sec
Reputation Power: 0
Question using 'printf' command and backquotes (")

hey am new to unix just wanted to know how to write a command that uses variable(s), the printf command and backquotes (") in order to print the correct number of files in a directory within a descriptive sentence. for example: 'your current directory (/home/abc123) has 12 files' . the command should run for any user.

i am not sure how to do this if any one can help it will be greatly appreatiated.

thank you,
sonya

Reply With Quote
  #2  
Old April 4th, 2005, 04:23 AM
zlutovsky zlutovsky is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Prague, Czech Rep.
Posts: 116 zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 22 h 34 sec
Reputation Power: 6
Quote:
Originally Posted by princesssonya
hey am new to unix just wanted to know how to write a command that uses variable(s), the printf command and backquotes (") in order to print the correct number of files in a directory within a descriptive sentence. for example: 'your current directory (/home/abc123) has 12 files' . the command should run for any user.

i am not sure how to do this if any one can help it will be greatly appreatiated.

thank you,
sonya


Hello sonya,

try this:

:
printf "your current directory %s has %s plain files\n" $(pwd) $(find . -type f | wc -l)

Copy and paste those two lines into the file scr.sh and then do the following:

chmod +x scr.sh
./scr.sh

This script will run under ksh or bash for any user that you allow. Read man chmod and some tutorial of shell programming.

Have a fun

Reply With Quote
  #3  
Old April 5th, 2005, 10:43 PM
princesssonya princesssonya is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 5 princesssonya User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 53 m 24 sec
Reputation Power: 0
help please

This is not working i get an illegal variable name error is it to do with the plain file bit can someone help please?
Sonya

Reply With Quote
  #4  
Old April 6th, 2005, 04:04 AM
zlutovsky zlutovsky is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Prague, Czech Rep.
Posts: 116 zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 22 h 34 sec
Reputation Power: 6
Quote:
Originally Posted by princesssonya
This is not working i get an illegal variable name error is it to do with the plain file bit can someone help please?
Sonya


Hello Sonya,

I have tested my two lines on a computer. They are realy OK. Can you copy your error message and say exactly what you did? What Unix do you use?


Reply With Quote
  #5  
Old April 6th, 2005, 06:16 AM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,083 guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 19 h 47 m 32 sec
Reputation Power: 9
Quote:
Originally Posted by zlutovsky
Hello sonya,

try this:

:
printf "your current directory %s has %s plain files\n" $(pwd) $(find . -type f | wc -l)

Copy and paste those two lines into the file scr.sh and then do the following:

chmod +x scr.sh
./scr.sh

This script will run under ksh or bash for any user that you allow. Read man chmod and some tutorial of shell programming.

Have a fun

hello zlutovsky
you are ASSUMING ksh or bash is running, every ASSUMPTION
is bad (4 a programmer)
try to do it working on EVERY env, it's simply the old way
(+= costs nothing more)
#!/bin/sh
HERE=`pwd`
FILES=`find $HERE -type f ¦ wc -l` # not really OK
# maybe a 'grep -c .' is faster
echo "your current directory $HERE has $FILES plain files"
__________________
working on Solaris[5-9], preferred languages french and C.

Reply With Quote
  #6  
Old April 6th, 2005, 07:52 AM
princesssonya princesssonya is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 5 princesssonya User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 53 m 24 sec
Reputation Power: 0
type of my shell

i am using cshell and i get an access denied error even though ive used chmod to change access to everyone even i dont undestand

Reply With Quote
  #7  
Old April 7th, 2005, 03:35 AM
zlutovsky zlutovsky is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Prague, Czech Rep.
Posts: 116 zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 22 h 34 sec
Reputation Power: 6
Quote:
Originally Posted by princesssonya
i am using cshell and i get an access denied error even though ive used chmod to change access to everyone even i dont undestand


Hello Sonya,

I do not know the C shell. But I have learned many years ago,
that the first line with single colon in it should cause the script to be executed by Bourne shell. And under Bourne shell it should run OK. So the script should be portable. Perhaps it is not so, I do not know.

You could try to put instead of my first line the line

#!"path to the Korn shell or Bourne again shell" i. e.

#!/usr/bin/ksh

or

#!/bin/bash

or whatever is correct in your Unix.

Regards

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > using 'printf' command and backquotes (")


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway