LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-30-2020, 11:11 AM   #1
.lance
LQ Newbie
 
Registered: Jan 2018
Posts: 1

Rep: Reputation: Disabled
Why does fedora and ubuntu doesn't have foreach command? What package should I install?


The title says it all. I was working on a red hat server at my work, I always use the foreach there. However, when I tried it on both my work stations that has ubuntu and fedora, it doesn't have the foreach command in it.

I tried to type in which foreach in the redhat server and it says that it's a built in command.

How can I get the foreach command to my fedora and ubuntu workstations?
 
Old 01-30-2020, 11:49 AM   #2
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,579
Blog Entries: 19

Rep: Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453
If it's a built-in command, that means it's part of whatever shell you're using. Bash doesn't have an explicit "foreach". The "for" command is a foreach in practice.
Bash man page:
for name [ [ in [ word ... ] ] ; ] do list ; done
The list of words following in is expanded, generating a list of items. The variable name is set to each element of this list in turn, and list is executed each time. If the in word is omitted, the for command executes list once for each positional parameter that is set.

I wonder if your Fedora server has "foreach" as an alias for "for"?
 
1 members found this post helpful.
Old 01-30-2020, 12:30 PM   #3
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,138
Blog Entries: 6

Rep: Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827
First couple of google hits

https://access.redhat.com/documentat...erence/ch07s04

https://www.cyberciti.biz/faq/bash-f...or-linux-unix/
 
1 members found this post helpful.
Old 01-30-2020, 04:07 PM   #4
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,579
Blog Entries: 19

Rep: Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453Reputation: 4453
Ah! Were you using csh on your Fedora server rather than bash?
 
Old 01-30-2020, 06:25 PM   #5
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Yes. What shell are you running on the Red Hat server at work, and what shell(s) are you running on the workstations?

foreach is a built-in in the c shell (csh), and, as stated, does not exist in bash.
 
1 members found this post helpful.
  


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
[SOLVED] No package 'x11' found No package 'xext' found No package 'xdamage' found No package 'xfixes' found No package 'x11-xcb' found Jigsaw Linux From Scratch 14 02-23-2021 08:35 PM
cat command inside foreach loop not working Praveen waliitagi Linux - Newbie 6 10-17-2013 02:09 AM
Why Perl's foreach loop can't use an array element as the control variable? password636 Programming 1 07-22-2011 09:58 AM
Stupid g++ compiler does not even support foreach loop, similarly for Visual C++ xuancong Programming 12 01-09-2011 10:58 PM
[SOLVED] Using foreach to run same command in several folders anhedonia Linux - Newbie 18 01-07-2011 04:26 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:39 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