Find the answer to your Linux question:
Results 1 to 2 of 2
Hi, I am trying to write a bash script to run some commands. The problem is that when I use the ls command, some filenames contain an asterix (*). This ...
  1. #1
    Just Joined!
    Join Date
    Sep 2006
    Posts
    12

    Bash script

    Hi,

    I am trying to write a bash script to run some commands. The problem is that when I use the ls command, some filenames contain an asterix (*). This * doesn't show up in konqueror, and it is giving me trouble executing my program.

    Why does this * appears, and how can I drop this last character?

    The scripts goes something like

    for i in `ls /directory`; do
    myProgram /directory/${i}
    done

    I need myProgram to receive the filename without the *.

    Thanx for your help.

  2. #2
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi, Mr M.

    You probably have an alias that really is doing ls -F when you enter ls. The "-F" adds some extra information on the end of the names it displays, "*" for executable, "/" for directory, etc. Most people find it convenient.

    You can usually avoid this by using /bin/ls instead of plain ls.

    I usually advise people to look at the man page, however, unless you looked carefully, you might not notice this in man ls, and, even if you did, the man page does provide any help on how to avoid it -- unless you intuit the method of not specifying the "-F".

    <digression> While I have not found the Linux man pages to be as useful as older Unix man pages, nevertheless I would still recommend that you read the man page on the command with which you having trouble. One of the advantages of those older man pages is that they often included examples to illustrate usage and to help avoid some common potential pitfalls. </digression>

    Best wishes ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

Posting Permissions

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