シェルの区切り文字

(16)
https://ja.stackoverflow.com/questions/17999/ifs%E3%81%AB%E6%94%B9%E8%A1%8C%E3%81%AE%E3%81%BF%E3%82%92%E6%8C%87%E5%AE%9A%E3%81%97%E3%81%9F%E3%81%84

echo $SHELL

: > a.txt
echo "1 2 3" >> a.txt
echo "4 5 6" >> a.txt
echo "7 8 9" >> a.txt

cat a.txt

-- 方法1
OLDIFS=$IFS
IFS='
'
for line in `cat a.txt` ; do
echo "${line}"
done

IFS=$OLDIFS

-- 方法2

OLDIFS=$IFS
IFS=$'\n'

for line in `cat a.txt` ; do
echo "${line}"
done

IFS=$OLDIFS

→どちらの方法でも区切り文字は動作する


(18)
echo $SHELL

: > a.txt
echo "1 2 3" >> a.txt
echo "4 5 6" >> a.txt
echo "7 8 9" >> a.txt

cat a.txt

-- 方法1
OLDIFS=$IFS
IFS='
'
for line in `cat a.txt` ; do
echo "${line}"
done

IFS=$OLDIFS

-- 方法2

OLDIFS=$IFS
IFS=$'\n'

for line in `cat a.txt` ; do
echo "${line}"
done

IFS=$OLDIFS

→どちらの方法でも区切り文字は動作する

 


(9)
echo $SHELL

: > a.txt
echo "1 2 3" >> a.txt
echo "4 5 6" >> a.txt
echo "7 8 9" >> a.txt

cat a.txt

-- 方法1
OLDIFS=$IFS
IFS='
'
for line in `cat a.txt` ; do
echo "${line}"
done

IFS=$OLDIFS

-- 方法2

OLDIFS=$IFS
IFS=$'\n'

for line in `cat a.txt` ; do
echo "${line}"
done

IFS=$OLDIFS

→どちらの方法でも区切り文字は動作する


(10)
echo $SHELL

: > a.txt
echo "1 2 3" >> a.txt
echo "4 5 6" >> a.txt
echo "7 8 9" >> a.txt

cat a.txt

-- 方法1
OLDIFS=$IFS
IFS='
'
for line in `cat a.txt` ; do
echo "${line}"
done

IFS=$OLDIFS

-- 方法2

OLDIFS=$IFS
IFS=$'\n'

for line in `cat a.txt` ; do
echo "${line}"
done

IFS=$OLDIFS

→どちらの方法でも区切り文字は動作する

(7)
echo $SHELL

: > a.txt
echo "1 2 3" >> a.txt
echo "4 5 6" >> a.txt
echo "7 8 9" >> a.txt

cat a.txt

-- 方法1
OLDIFS=$IFS
IFS='
'
for line in `cat a.txt` ; do
echo "${line}"
done

IFS=$OLDIFS

-- 方法2

OLDIFS=$IFS
IFS=$'\n'

for line in `cat a.txt` ; do
echo "${line}"
done

IFS=$OLDIFS

→どちらの方法でも区切り文字は動作する

(8)

echo $SHELL

: > a.txt
echo "1 2 3" >> a.txt
echo "4 5 6" >> a.txt
echo "7 8 9" >> a.txt

cat a.txt

-- 方法1
OLDIFS=$IFS
IFS='
'
for line in `cat a.txt` ; do
echo "${line}"
done

IFS=$OLDIFS

-- 方法2

OLDIFS=$IFS
IFS=$'\n'

for line in `cat a.txt` ; do
echo "${line}"
done

IFS=$OLDIFS

→どちらの方法でも区切り文字は動作する

 

(2012R2)
https://www.adminweb.jp/command/bat/index10.html

type nul > a.txt
echo 1 2 3 >> a.txt
echo 4 5 6 >> a.txt
echo 7 8 9 >> a.txt

type a.txt

@echo off
for /f "tokens=*" %%a in (a.txt) do (
echo %%a
)


(2016)
type nul > a.txt
echo 1 2 3 >> a.txt
echo 4 5 6 >> a.txt
echo 7 8 9 >> a.txt

type a.txt

@echo off
for /f "tokens=*" %%a in (a.txt) do (
echo %%a
)

(2019)
type nul > a.txt
echo 1 2 3 >> a.txt
echo 4 5 6 >> a.txt
echo 7 8 9 >> a.txt

type a.txt

@echo off
for /f "tokens=*" %%a in (a.txt) do (
echo %%a
)