Find the answer to your Linux question:
Page 2 of 2 FirstFirst 1 2
Results 11 to 16 of 16
Originally Posted by Cancerous Any command that will contain spaces needs to have the content wrapped in quotes, otherwise it reads them as seperate commands. Just change this line so ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #11
    Just Joined!
    Join Date
    Nov 2012
    Posts
    18

    Quote Originally Posted by Cancerous View Post
    Any command that will contain spaces needs to have the content wrapped in quotes, otherwise it reads them as seperate commands.

    Just change this line so it looks like this.

    Code:
    echo "$i file"

    Also, homework is against the forum rules. So we shouldn't be solving it for you, just pointing you in the right direction.
    Anyone of you mind checking my post, and help me with explaination of codes. I do need help, anyone who mind giving me some tutorial.

    I'm eager to learn, but youtube is too much on the surface, I believe learning from reading and understanding is beneficial.

    Any scripter who dont mind sharing your scripts with well-written comment code ?

    I need help myself too.

  2. #12
    Just Joined!
    Join Date
    May 2012
    Posts
    43
    I'm relatively new to scripting myself, but luckily I'm learning on the job and work with some very helpful people.

    A lot of what I've learnt is just through googling "how to do [/I]x job[/I] in bash", also looking at forums like this one, looking at what other people post and then analyzing their solutions helps a lot.

    Start off small, and then work your way up. If you've got no previous experience in programming then this will help a lot (I knew Visual Basic before I started learning bash).

    Read the man pages for what you want to do. eg
    Code:
    man echo
    Write the scripts yourself! I cannot stress this enough. Copying and pasting someone elses work will not teach you anything. Type it out, run it then mess with it a bit. Change something and see what changes in the script.

  3. #13
    Just Joined!
    Join Date
    Nov 2012
    Posts
    9
    Code:
    #! /bin/csh
    foreach x ( `ls` )
    echo $x
    set mycnt=`grep -l $1 * | wc -l`
    echo $mycnt
    end
    I got it to display the files in the directory but when I added the 2 lines after echo $x so that i can echo the number of files in the directory it keeps bring up zero's.
    Last edited by atreyu; 11-20-2012 at 03:43 AM. Reason: added code tags to aid in readability

  4. $spacer_open
    $spacer_close
  5. #14
    Just Joined!
    Join Date
    May 2012
    Posts
    43
    It works for me.
    Are you working in a directory with files in it?

  6. #15
    Just Joined!
    Join Date
    Nov 2012
    Posts
    9
    yes I am, it has several files inside the directory.

  7. #16
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Quote Originally Posted by Chris4610 View Post
    set mycnt=`grep -l $1 * | wc -l`
    jc, what is the point of the $1 in this code?

Page 2 of 2 FirstFirst 1 2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •