Skip to main content
added 72 characters in body
Source Link
Prvt_Yadav
  • 6k
  • 7
  • 39
  • 52

You can use ${i%%.*}. It will remove everything after first occurrence of dot including dot.

e.g.

i=absdfsfd.b.c.dddd
echo "${i%%.*}"

will give output

absdfsfd

In your case:

 for i in *;do echo "${i%%.*}";done

Well do not use for i in ls. See Why *not* parse `ls` (and what to do instead)?

You can use ${i%%.*}

e.g.

i=absdfsfd.b.c.dddd
echo "${i%%.*}"

will give output

absdfsfd

In your case:

 for i in *;do echo "${i%%.*}";done

Well do not use for i in ls. See Why *not* parse `ls` (and what to do instead)?

You can use ${i%%.*}. It will remove everything after first occurrence of dot including dot.

e.g.

i=absdfsfd.b.c.dddd
echo "${i%%.*}"

will give output

absdfsfd

In your case:

 for i in *;do echo "${i%%.*}";done

Well do not use for i in ls. See Why *not* parse `ls` (and what to do instead)?

added 51 characters in body
Source Link
Prvt_Yadav
  • 6k
  • 7
  • 39
  • 52

You can use ${i%%.*}

e.g.

i=absdfsfd.b.c.dddd
echo "${i%%.*}"

will give output

absdfsfd

In your case:

 for i in *;do echo "${i%%.*}";done

Well do not use for i in ls. See Why *not* parse `ls` (and what to do instead)?

You can use ${i%%.*}

e.g.

i=absdfsfd.b.c.dddd
echo "${i%%.*}"

will give output

absdfsfd

In your case:

 for i in *;do echo "${i%%.*}";done

Well do not use for i in ls.

You can use ${i%%.*}

e.g.

i=absdfsfd.b.c.dddd
echo "${i%%.*}"

will give output

absdfsfd

In your case:

 for i in *;do echo "${i%%.*}";done

Well do not use for i in ls. See Why *not* parse `ls` (and what to do instead)?

deleted 160 characters in body
Source Link
Prvt_Yadav
  • 6k
  • 7
  • 39
  • 52

You can use ${i%%.*}

e.g.

i=absdfsfd.b.c.dddd
echo "${i%%.*}"

will give output

absdfsfd

In your case:

 for i in *;do echo "${i%%.*}";done

Well do not use for i in ls.

And if you really want to use pipes, then you can do

echo $(echo $i|cut -d. -f1)

In your case:

for i in *;do echo "$(echo $i|cut -d. -f1)";done

You can use ${i%%.*}

e.g.

i=absdfsfd.b.c.dddd
echo "${i%%.*}"

will give output

absdfsfd

In your case:

 for i in *;do echo "${i%%.*}";done

Well do not use for i in ls.

And if you really want to use pipes, then you can do

echo $(echo $i|cut -d. -f1)

In your case:

for i in *;do echo "$(echo $i|cut -d. -f1)";done

You can use ${i%%.*}

e.g.

i=absdfsfd.b.c.dddd
echo "${i%%.*}"

will give output

absdfsfd

In your case:

 for i in *;do echo "${i%%.*}";done

Well do not use for i in ls.

added 164 characters in body
Source Link
Prvt_Yadav
  • 6k
  • 7
  • 39
  • 52
Loading
missing quotes
Source Link
Stéphane Chazelas
  • 587k
  • 96
  • 1.1k
  • 1.7k
Loading
deleted 3 characters in body
Source Link
Prvt_Yadav
  • 6k
  • 7
  • 39
  • 52
Loading
Source Link
Prvt_Yadav
  • 6k
  • 7
  • 39
  • 52
Loading