LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-20-2018, 03:48 PM   #1
trainspotting
LQ Newbie
 
Registered: Apr 2018
Distribution: Ubuntu, Mint
Posts: 8

Rep: Reputation: Disabled
First language question - Batch


Hey This is my first time with a language, so don't yet know all the bassic rules

How do you tell a bat script to open a path and sellect random - how do you set a path like this start C:\Users\Music\%random% ? (how do use random)


also can you tell it to save results in a text file
 
Old 04-20-2018, 04:57 PM   #2
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
you're thinking Linux is Windows, stop that.
Linux does not have bat files, nor directory assignment like, a:\ b:\ c:\ d:\

what you need to do is read up on BASH scripting and Linux fundamentals, first, and not exactly in that order.

this might be your second time with a language, your native language is you're first time with a language, actually. FYI.

Last edited by BW-userx; 04-20-2018 at 05:09 PM.
 
Old 04-20-2018, 05:28 PM   #3
dogpatch
Member
 
Registered: Nov 2005
Location: Central America
Distribution: Mepis, Android
Posts: 490
Blog Entries: 4

Rep: Reputation: 238Reputation: 238Reputation: 238
Am not a Windows user, but this page may get you started
 
Old 04-20-2018, 06:00 PM   #4
bodqhrohro
Member
 
Registered: Apr 2018
Location: Ukraine
Distribution: Debian GNU/Linux 12
Posts: 62

Rep: Reputation: Disabled
Quote:
Originally Posted by BW-userx View Post
Linux does not have bat files, nor directory assignment like, a:\ b:\ c:\ d:\
However Wine brings all of it .bat support is one of the few things it does well
 
1 members found this post helpful.
Old 04-20-2018, 06:12 PM   #5
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
No mention of “ I’m using wine in Linux, how do I do windows stuff in wine?”

Therefore even so, it’d still fall under windows forum not Linux
 
Old 04-20-2018, 06:49 PM   #6
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Technically, Programming is in Non-*NIX forum at LQ
 
1 members found this post helpful.
Old 04-20-2018, 08:06 PM   #7
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
it could be argued writing bat(ch) files is not a programming language. in the same argument held to BASH scripting is not programming. per se'

anyways that word 'batch' threw me I have not heard it called batch file in many years, so it did not registered until now, I only recalled bat file and associated it windows, along with the rest of that windows lingo.

though it is a challenging question.

Last edited by BW-userx; 04-20-2018 at 08:09 PM.
 
Old 04-21-2018, 12:02 PM   #8
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,725

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Dogpatch's link looks most helpful...some good hints there. Give those a shot and come back with any questions.

Quote:
Originally Posted by BW-userx View Post
I have not heard it called batch file in many years, so it did not registered until now, I only recalled bat file and associated it windows, along with the rest of that windows lingo.
Yes. "batch file" invoked memories of JCL on IBM and WFL on Burroughs in addition to .bat on Windows (which I still have rare occasion to write/maintain)

Edit: I put "windows batch file tutorial" into my favorite search engine and got a page full of guides, basics, and tutorials.

Last edited by scasey; 04-21-2018 at 12:04 PM.
 
Old 04-21-2018, 06:35 PM   #9
trainspotting
LQ Newbie
 
Registered: Apr 2018
Distribution: Ubuntu, Mint
Posts: 8

Original Poster
Rep: Reputation: Disabled
Ok guys I'm sensing some elitism here ....? calm down shhhhhhhhh shhhhhhh (slow hug) shhhhhhh

I'm just asking for simple\common rules (more then one way to skin a cat)

Show me how to use random in batch - I can make menu's but never messed with file path (learn by seeing\doing\talking)

I think bat files falls under programming language ? - Have used Windows for awhile & Batch seemed like a good place to start ?
I'm having fun with it anyway and Linux is for anything computer related ?

"However Wine brings all of it .bat support is one of the few things it does well"

- Using wine to run Notepad++ - The layout is helpful.

Just exploring & tinkering. Would like to see how games are made or need to find something.
 
Old 04-21-2018, 09:10 PM   #10
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,680

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894
I would probably pick any other script/programming language besides a batch file ...

%random% is a pseudorandom number generator that has a range of 0-32767. You can find many examples of how to set a range but typically you use the modulo function. For Example to output a range from 1-10 the equation is:
Code:
set /a num=%random% %%10 +1 
echo %num%
random is seeded by the DOS clock which only updates once per second.
 
Old 04-22-2018, 04:02 PM   #11
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,649
Blog Entries: 4

Rep: Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934
I would agree with michaelk. In the Linux/Unix environment you can "write a batch file" in any language – Ruby, Perl, PHP, Python, and more – just by putting #!command_processor_path ("shebang") as the first line. You do not have to limit yourself to the built-in scripting facilities of the bash shell. (Only Dr. Korn's shell ever attempted to have a "real" programming language "built-in.")

And, even in Windows, you now have PowerShell, which, although it's a very different beast, is also significantly more powerful than ".bat files."

Last edited by sundialsvcs; 04-22-2018 at 04:04 PM.
 
Old 04-22-2018, 06:26 PM   #12
trainspotting
LQ Newbie
 
Registered: Apr 2018
Distribution: Ubuntu, Mint
Posts: 8

Original Poster
Rep: Reputation: Disabled
Honestly Linux is new & strange to me - played with CMD\bat awhile back & having fun learning how to make a menu.

Is Programming Algebra, is that the best way to see it ?

"%random% is a pseudorandom number generator that has a range of 0-32767"

That's the problem I'm struggling to talk (begginer) I ment how to make the program pick a random path\selection

C:\%User%\Music\Gaming\

^
How to set random

set /a num=%random% %%10 +1
echo %num%

^
Can you alter the refress ?


The save to text was (> greater than) { C:\ > ipconfig >save name.txt }

"– just by putting #!command_processor_path ("shebang") as the first line. You do not have to limit yourself to the built-in scripting facilities of the bash shell."

It's seems useful to know Windows commands \ self built tools. What language whould you guys recommend (simple,games,menus,apps) ?
 
Old 04-22-2018, 10:57 PM   #13
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,649
Blog Entries: 4

Rep: Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934
trainspotting, "colleague to colleague" I would reply to you ... that you have truly stumbled-into an entirely different (yet, "parallel, all this time ...") ... ...

... ...

... world.

Nothing that you may have learned from "Windows batch files" applies to you equally here ... and vice-versa.
 
Old 04-23-2018, 08:51 AM   #14
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,680

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894
I have not played with batch files in a long time. If you want to go with a scripting language that is cross platform then try Perl, Python, Ruby or PHP.
The shebang is a linux scripting thing and not applicable in Windows.

I would think learning PowerShell would be more useful than batch programming.

Code:
@echo off
setlocal enabledelayedexpansion
set list[0]=path_one
set list[1]=path_two
set list[2]=path_three

set /a num=%random% %%3 
echo %num%
call echo !list[%num%]!
 
Old 04-23-2018, 01:31 PM   #15
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,219

Rep: Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309
I thought BASH was the standard scripting environment for Windows now?
 
  


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
DOS Batch question (yes i know...) watcher69b General 1 03-17-2009 11:14 AM
xp batch script question babag Programming 8 01-31-2007 02:52 PM
Batch rename question hellblade Linux - Software 4 05-03-2004 03:57 PM
Batch Question hornet74 Linux - General 2 02-02-2004 04:39 PM
Linux Backup Batch question lowly_tech Linux - Newbie 2 01-09-2002 04:02 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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